I have a problem with Angular 2. I want to made List HTML like this:
<ul>
<li>
<li>..
</ul>
With links but I don't know how to add iterate argument to HTML object in NG2. It is my code:
<ul>
<li *ngFor="let item of geoNames | filterBy: userFilter"
(click)="showNameG= !showNameG" >
<a>{{ item.name }}</a>
</li>
</ul>
<div *ngIf="showNazwyG">
<show-NameG></show-NameG>
</div>
And I want to add a different name to each of the element li to recognize from has been clicked. In AngularJS worked something like this:
(click)="showNameG{{index}}= !showNameG{{index}}"
*ngFor provides an index context variable
<li *ngFor="let item of geoNames | filterBy: userFilter; let i=index"
(click)="showNameG[i]= !showNameG[i]" ><a>{{ item.name }}</a></li>
update
<li *ngFor="let item of geoNames | filterBy: userFilter; let i=index"
(click)="self['showNameG'] + i = !self['showNameG']" ><a>{{ item.name }}</a></li>
export class MyComponent {
get self() {
return this;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With