问题
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