作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
尝试执行以下操作并出现“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/
我是一名优秀的程序员,十分优秀!