【问题标题】:Angular using pipes and index in ngForAngular 在 ngFor 中使用管道和索引
【发布时间】: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 undefinedParser Error: Unexpected token |

【问题讨论】:

  • ngFor 表达式的末尾删除| 管道..
  • 是的,并将其替换为分号。 let x of y | zzz; let index=index
  • @dbandstra 更改了代码,仍然出现相同的错误 =/

标签: angular


【解决方案1】:

试试下面,

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

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2017-03-13
    • 2018-04-18
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    相关资源
    最近更新 更多