Angular在测试版中有很多变化,我的问题是尝试在ngFor中使用管道和索引,我收到此消息:
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;
我如何同时使用管道和索引?
修改 我修改了代码,如下所示:
<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 |
答案 0 :(得分:10)
尝试以下,
<div (click)="showComentario(i)" *ngFor="let comment of comentarios | filterSource : selectedSource; index as i" >
{{comment.comment}}
</div>
希望这会有所帮助!!