【问题标题】:Got interpolation ({{}}) where expression was expected with angular得到了插值({{}}),其中表达式预期带有角度
【发布时间】:2019-08-04 00:03:41
【问题描述】:

我的代码出现 angular 6 错误

<span *ngFor="let tag of item.payload.doc.data().TAGS" > 
                    <button class="nav-link active" (click)="searchByTags('{{tag}}')" >{{tag}},</button>
                </span>

我想在 searchByTags 函数中加入动态 {{tag}} 但它给了我下一个错误:

Parser Error: Got interpolation ({{}}) where expression was expected at column 14 in [searchByTags('{{tag}}')] in ng:///AppModule/HomeComponent.html@76:56 ("et tag of item.payload.doc.data().TAGS" > 
                    <button class="nav-link active" [ERROR ->](click)="searchByTags('{{tag}}')" >{{tag}},</button>
                </span>

【问题讨论】:

  • 把这个(click)="searchByTags('{{tag}}')"改成这个(click)="searchByTags(tag)"

标签: angular


【解决方案1】:

将您的代码更改为:

<span *ngFor="let tag of item.payload.doc.data().TAGS" > 
    <button class="nav-link active" (click)="searchByTags(tag)" >{{tag}},</button>
</span>

您不需要在点击处理程序中插入标记值。您可以直接传递值而无需插值。

【讨论】:

    猜你喜欢
    • 2017-07-16
    • 1970-01-01
    • 2017-10-31
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    相关资源
    最近更新 更多