尝试执行以下操作并出现“Got interpolation ({{}}) where expression was expected”错误。
<ul>
<li *ngFor="#item of items">
<a href='' (click)="foo('{{item.name}}')">{{item.name}}</a>
</li>
</ul>
谢谢!
最佳答案
不要在任何事件处理程序代码(在 View 上)中使用 {{}}
(插值),直接传递表达式,这将针对 Component
上下文进行评估(this
),就像在这里您试图将 item.name
传递给 foo
函数一样。所以删除 {{}}
括号就可以了。
<a href="" (click)="foo(item.name)">
{{item.name}}
</a>
关于events - 绑定(bind)中的 Angular 2 绑定(bind)。事件内插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36659854/