得到了插值({{}}),其中期望用角表示

时间:2019-03-13 10:33:03

标签: angular

我的角度为6的代码出现错误

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

我想将动态{{tag}}放入searchByTags函数中,但这会给我带来下一个错误:

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>

1 个答案:

答案 0 :(得分:0)

将代码更改为此:

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

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