【发布时间】:2018-05-12 00:40:00
【问题描述】:
像这样在 ngFor 中循环遍历数组:
<div *ngFor="account of accounts">
<button (click)="function1(); account.message='How do I interpolate {{account.something}} here'"
</div>
我收到错误Got interpolation ({{}}) where expression was expected
如果我只是在没有插值的情况下执行account.something,因为它位于单引号之间,它将打印为文字How do I interpolate account.something
【问题讨论】:
-
我通常发现最好在绑定中包含尽可能少的逻辑和代码。我建议在你的模块中放置一个单独的处理程序,并让点击处理程序读取
(click)="function2(account)"。
标签: javascript angular angular5 string-interpolation