Passing ngFor variable to an ngIf template

All you need is to use [ngTemplateOutletContext] Read More Here is the way how you can achieve that : <div> <h3>All Templates</h3> <ul *ngFor=”let number of numbers”> <ng-container [ngTemplateOutlet]=’number % 2 == 0 ? even_tpl : odd_tpl’ [ngTemplateOutletContext]=”{number:number}”></ng-container> </ul> </div> <ng-template #odd_tpl let-number=”number”> <li>Odd: {{number}}</li> </ng-template> <ng-template #even_tpl let-number=”number”> <li>Even: {{number}}</li> </ng-template> WORKING DEMO

Dynamically assign element id inside ngFor

You can use {{ ‘wave’ + i }} instead of wave{{i}}. Make it as Angular Experession. This is the full ngFor: <li *ngFor=”let episode of episodes; let i = index”> <div id=”{{ ‘wave’ + i }}”></div> </li> It works and creates the div with the correct id document.getElementById(“wave1″) Output will be like this: <div id=​”wave1”>​wave1​</div> … Read more

Angular 2: Callback when ngFor has finished

You can use @ViewChildren for that purpose @Component({ selector: ‘my-app’, template: ` <ul *ngIf=”!isHidden”> <li #allTheseThings *ngFor=”let i of items; let last = last”>{{i}}</li> </ul> <br> <button (click)=”items.push(‘another’)”>Add Another</button> <button (click)=”isHidden = !isHidden”>{{isHidden ? ‘Show’ : ‘Hide’}}</button> `, }) export class App { items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; … Read more

angular viewChild for dynamic elements inside ngFor

TL;DR Use ViewChildren instead of ViewChild As @Commerical Suicide mentioned you cannot set the references dynamically. The #div is called template reference variable. You can access your divs via ViewChildren in you *.ts file. Sample: @ViewChildren(‘div’) divs: QueryList<ElementRef> Then you can call multiple methods on your new QueryList, like forEach or find.

How to create variable in ngFor loop?

I think local variables (defined with the # character) don’t apply for your use case. In fact, when you define a local variable on an HTML element it corresponds to the component if any. When there is no component on the element, the variable refers to the element itself. Specifying a value for a local … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)