Search code examples
angularangular2-routingangular2-templateangular2-formsangular2-directives

how to value is assign to reference variable in angular 2?


<ng-container  *ngFor="let item of users">
                        <td  *ngIf="item.method == update.business_type">{{item.id}}</td>
</ng-container>

how to item.id value is assign to refernce variable.I tried but its not working


Solution

  • You will need to create the *ngLet or *ngFor directive by following reference link:

    https://medium.com/@AustinMatherne/angular-let-directive-a168d4248138

    This is the way I declare the variables into templates after creating the directives:

    <ng-container  *ngFor="let item of users">
        <ng-container *ngLet="item.id as ref_var">
            <td  *ngIf="item.method == update.business_type">{{ref_var}}</td>
        </ng-container>
    </ng-container>
    

    This is also possible using *ngVar directive:

    <ng-container  *ngFor="let item of users">
        <ng-container *ngVar="item.id as ref_var">
            <td  *ngIf="item.method == update.business_type">{{ref_var}}</td>
        </ng-container>
    </ng-container>