i\'m learning AngularJS, and i need some help.
I have a template like this
Get an array as property on your class. Each time your function is called, set the corresponding item (say i) of this array to the value. And in the template reference the i item of that same array.
this.data = dataFromSomewhere();
this.dataOpt = this.data.map((d) => this.myFunction(d.id));
<div *ngFor="let beat of data; let i=index" class="item">
<div>{{dataOpt[i]}}</div>
The pipe variant:
@Pipe({selector: myFunc})
class MyPipy implements PipeTransform {
transform(val:string) {
return // do the same calculation here that you would do in `myFunction`;
}
}
and use it like
<div *ngFor="let beat of data; let i=index" class="item">
<div>{{data | myPipe}}</div>
(the pipe needs to be registered in declarations of the module (or in an imported module)