Home:ALL Converter>How to call a method in component for every iteration in *ngFor in angular2?

How to call a method in component for every iteration in *ngFor in angular2?

Ask Time:2016-06-16T20:41:19         Author:Bhushan Gadekar

Json Formatter

I want to call a method for every iteration of *ngFor and pass the iterated variable in the method.

for eg.

<li *ngFor="let element of componentModel | keys">{{element.key}}--{{element.value}}</li>

then I have this method in component as:

loadProperty(element:any){
   console.log(element.key);
   console.log(element.value);
}

I want this function to get called for every iteration and pass every value of iterated variable.

any inputs?

Author:Bhushan Gadekar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37859572/how-to-call-a-method-in-component-for-every-iteration-in-ngfor-in-angular2
yy