ngFor - Get item from loop to call it in a function

Viewed 94

I have a table containing the list of feedback. I'm trying to call the function on each looped item.

HTML File:

<ng-container *ngFor="let fd of feedbacks;let i = index">
   <tr>
     <td>{{ i + 1 }}</td>
     <td>{{ fd.feedback }}</td>
     <td><button (click)="Analyzer(fd.feedback)">Click me!</button></td>
   </tr>
     </ng-container>

Attempted action : Set each item as argument to Analyzer() function.

2 Answers

What is the problem?

If you have a function defined in the .ts file

Analyzer(feedback: string) { /* .. */ }

Then what you have will work

Your code is perfectly fine! Please make sure you have the method Analyzer() defined in your .ts file. Also, I would add as a recommendation that methods should start with a lowercase letter, in your case would be analyzer(), but take this just as a recommendation.

Related