【问题标题】:Angular 2 binding within binding. Interpolation within event绑定中的 Angular 2 绑定。事件内插值
【发布时间】:2016-08-08 04:14:23
【问题描述】:

尝试执行以下操作并得到 “Got interpolation ({{}}) where expression is expected” 错误。

<ul>
  <li *ngFor="#item of items">
    <a href='' (click)="foo('{{item.name}}')">{{item.name}}</a>
  </li>
</ul>

谢谢!

【问题讨论】:

    标签: events binding angular interpolation


    【解决方案1】:

    不要在任何事件处理程序代码(在视图上)中使用{{}}(interpolation),直接传递表达式,它将根据Component context(this) 进行评估,就像在这里你正在尝试将item.name 传递给foo 函数。所以删除 {{}} 括号就可以了。

    <a href="" (click)="foo(item.name)">
      {{item.name}}
    </a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 2017-06-25
      • 2018-02-02
      • 2017-11-05
      • 1970-01-01
      相关资源
      最近更新 更多