ngFor中使用管道和索引的角度 [英] Angular using pipes and index in ngFor
本文介绍了ngFor中使用管道和索引的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Angular在beta中有很多更改,我的问题是尝试在ngFor中使用管道和索引,但我得到了以下消息:
Angular had many changes in the beta, my issue is that try to use pipes and the index in a ngFor and i get this message:
Parser Error: Unexpected token =
和
The pipe 'let' could not be found
当我使用此代码时:
<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>
如果我这样更改订单:
<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>
我收到此消息:
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 i can use pipes and index at the same time?
我将代码修改为如下所示的注释:
I modified the code as the comments suggested like this:
<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>
我不断收到这些错误:
TypeError: key[0] is undefined
和Parser Error: Unexpected token |
i keep getting these errors:
TypeError: key[0] is undefined
and Parser Error: Unexpected token |
推荐答案
请尝试以下
<div (click)="showComentario(i)" *ngFor="let comment of comentarios | filterSource : selectedSource; index as i" >
{{comment.comment}}
</div>
希望这会有所帮助!
这篇关于ngFor中使用管道和索引的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文