绑定内的角度2绑定.事件内插 [英] Angular 2 binding within binding. Interpolation within event
本文介绍了绑定内的角度2绑定.事件内插的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试执行以下操作,并出现期望插入表达式的插值({{}})" 错误.
Trying to do the following and getting "Got interpolation ({{}}) where expression was expected" error.
<ul>
<li *ngFor="#item of items">
<a href='' (click)="foo('{{item.name}}')">{{item.name}}</a>
</li>
</ul>
谢谢!
推荐答案
不要在任何事件处理程序代码(在视图中)内使用{{}}
(插值),而是直接传递表达式,该表达式将针对Component
context(this
),就像在这里一样,您试图将item.name
传递给foo
函数.因此,删除{{}}
括号即可解决问题.
Don't use {{}}
(interpolation) inside any event handler code (on a view), do pass expression directly which will get evaluated against Component
context(this
), like over here you're trying to pass item.name
to foo
function. So removing {{}}
parenthesis would do the trick.
<a href="" (click)="foo(item.name)">
{{item.name}}
</a>
这篇关于绑定内的角度2绑定.事件内插的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文