Mandar Shinde

Mandar Shinde

  • NA
  • 423
  • 110.1k

Regarding call a function using ngFor in Angular 6.

Aug 29 2019 12:38 AM
Dear all,
I hope you are doing well. While creating one component using Angular 6 and ASP .Net MVC I am facing one problem.
I have one one array and I want to print it in a table so for I am using ngFor loop.
I want to call a function for every row. How can I do that?
What I have tried is :-
 
  1. <table class="table">        
  2.    <tr>        
  3.      <th>#</th>        
  4.      <th>Game</th>        
  5.      <th>Platform</th>         
  6.       <th>Release</th>        
  7.     </tr>        
  8.      <tr *ngFor="let game of games; let i = index; trackBy:GameName(i)">        
  9.           <td>{{i + 1}}</td>        
  10.           <td>{{game.game}}</td>        
  11.           <td>{{game.platform}}</td>        
  12.           <td>{{game.release}}</td>        
  13.       </tr>        
  14. </table>    
 in ts :-
 
  1. GameName(index){  
  2. alert(index);  
  3. }  
If I run above code then it returns undefined for infinite time. I want to cal that function till only length of array. 
 
Please let me know if you have any suggestions.
Thanking you in advance. 

Answers (3)