ngFor 中的字符串插值 (click)="..."
String interpolation inside ngFor (click)="..."
像这样在 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)="account.message='How do I interpolate ' + account.something + ' here'"
你已经打算在双引号里面写javascript,所以你不需要写插值语法。
(click)="All javascript code can be written here without interpolation syntax"
像这样在 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)="account.message='How do I interpolate ' + account.something + ' here'"
你已经打算在双引号里面写javascript,所以你不需要写插值语法。
(click)="All javascript code can be written here without interpolation syntax"