Angular 2 binding within binding. Interpolation within event

落爺英雄遲暮 提交于 2019-12-10 03:38:39

问题


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>

Thanks!


回答1:


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>


来源:https://stackoverflow.com/questions/36659854/angular-2-binding-within-binding-interpolation-within-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!