ngFor(click)=" ..."内的字符串插值

时间:2018-05-11 16:27:52

标签: javascript angular angular5 string-interpolation

在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

2 个答案:

答案 0 :(得分:3)

只需使用字符串连接,如:

$date = "4/20/2019";
if( validateDateFormats($date, 'm/d/Y')
    ||  validateDateFormats($date, 'n/d/Y') ){
    print "This date is valid."; 
}

答案 1 :(得分:0)

你已经在双引号内写了javascript,所以你不需要编写插值语法。

(click)="All javascript code can be written here without interpolation syntax"