Saturday 11 March 2017

[SOLVED]How *ngFor works with template variables in angular 2?

```
<event-thumbnail *ngFor='let event1 of events' #thumbnail  [event2]="event1" (eventClick)='handleEventClicked($event)'>Hello</event-thumbnail>
<button class='btn btn-primary' (click)="thumbnail.alertFoo()">alert id</button>
<button class='btn btn-primary' (click)='thumbnail.handleClickMe()'>click me!</button>
```

In the above code I am unable to use button using thumbnail -> template variable when using *ngFor. I also tried to wrap it inside div and still it doesnt work. It only works when I am enclosing the whole code inside a div with *ngFor i.e. also buttons which displays undesirable multiple buttons. I want to understand how ngFor works is there some work around for the above where i want events to be repeated but the buttons to be displayed only once.


via Atharva Pandey

No comments:

Post a Comment