加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在ngFor中使用管道和索引的角度

发布时间:2020-12-17 17:54:52 所属栏目:安全 来源:网络整理
导读:Angular在测试版中有很多变化,我的问题是尝试在ngFor中使用管道和索引,我收到此消息: 分析器错误:意外的令牌=和 The pipe 'let' could not be found 当我使用这段代码时: div style="overflow-y: scroll; max-height: 200px;" div (click)="showComentari
Angular在测试版中有很多变化,我的问题是尝试在ngFor中使用管道和索引,我收到此消息:

分析器错误:意外的令牌=和

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]未定义,Parser Error:意外的令牌|

解决方法

试试下面,

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

希望这可以帮助!!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读