【发布时间】:2017-05-17 17:35:20
【问题描述】:
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;
如何同时使用管道和索引?
编辑: 我按照 cmets 的建议修改了代码,如下所示:
<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 |
【问题讨论】:
-
从
ngFor表达式的末尾删除|管道.. -
是的,并将其替换为分号。
let x of y | zzz; let index=index -
@dbandstra 更改了代码,仍然出现相同的错误 =/
标签: angular