Angular using pipes and index in ngFor

Angular had a lot of changes in beta, my problem is trying to use channels and index in ngFor and I get this message:

Parser Error: Unexpected token =

and

The pipe 'let' could not be found  

      

when i use this code:

 <div style="overflow-y: scroll; max-height: 200px;">
        <div (click)="showComentario(index);" *ngFor="let comment of comentarios| filterSource:selectedSource | let index=index; ">
            {{comment.comment}}
        </div>
    </div>

      

if i change the order like this:

<div style="overflow-y: scroll; max-height: 200px;">
    <div (click)="showComentario(index);" *ngFor="let comment of comentarios;let index=index;| filterSource:selectedSource |  ">
        {{comment.comment}}
    </div>
</div>

      

I am getting this message:

Template parse errors:
TypeError: key[0] is undefined  



Parser Error: Unexpected token |, expected identifier, keyword, or string at column 47 in [let comment of comentarios; let index=index; 

      

How can I use pipes and index at the same time?

EDIT: I changed the code as comments suggested as follows:

<div style="overflow-y: scroll; max-height: 200px;">
    <div (click)="showComentario(index);" *ngFor="let comment of comentarios | filterSource:selectedSource;let index=index ">
        {{comment.comment}}
    </div>
</div>

      

I keep getting these errors: TypeError: key[0] is undefined

andParser Error: Unexpected token |

+3


source to share


1 answer


try below,

<div (click)="showComentario(i)" *ngFor="let comment of comentarios | filterSource : selectedSource; index as i" >
  {{comment.comment}}
</div>

      



Hope this helps!

+5


source







All Articles