Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Pass variable to ng-template

I have this ng-template. Everything works with the loop. The only problem is that i can't pass the "title" variable with the "let-title".

What's wrong with my syntax? Do I need the asterisk to *ngIf?

"selectPerm(title)" doesn't work. It is always undefined.

<ng-template ngFor
             let-perm
             let-title="permission.title"
             [ngForOf]="permission.data.permissions"
             *ngIf="editForm.controls.permissions.controls[permission.data.id].value == '0'">
             <tr>
                <td></td>
                <td>{{perm.name}}</td>
                <td><label>Allow: <input type="radio" value="1" formControlName="{{perm.id}}" (click)="selectPerm(title)"></label></td>
                <td><label>Deny: <input type="radio" value="-1" formControlName="{{perm.id}}" (click)="selectPerm(title)"></label></td>
                <td></td>
             </tr>
</ng-template>
like image 214
Michalis Avatar asked Mar 02 '26 15:03

Michalis


1 Answers

Try placing your *ngIf on your "tr" tag and then referencing perm.title instead of a template input variable:

<ng-template ngFor
         let-perm
         [ngForOf]="permission.data.permissions">
         <tr *ngIf="editForm.controls.permissions.controls[permission.data.id].value == '0'">
            <td></td>
            <td>{{perm.name}}</td>
            <td><label>Allow: <input type="radio" value="1" formControlName="{{perm.id}}" (click)="selectPerm(perm.title)"></label></td>
            <td><label>Deny: <input type="radio" value="-1" formControlName="{{perm.id}}" (click)="selectPerm(perm.title)"></label></td>
            <td></td>
         </tr>
</ng-template>
like image 135
birwin Avatar answered Mar 05 '26 05:03

birwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!