in Angular 2 we have several way to create property bindings in templates. I could do something like this:
<li *ngFor="#course of courses; #i = index" id="someselector-{{i}}">{{course}}</li>
Is it possible to obtain the same result using the square brakets syntax?
<li *ngFor="#course of courses; #i = index" [id]="someselector-i">{{course}}</li>
^^^^^^^
how create string concatenation?
Thanks, G.
答案 0 :(得分:41)
我发现你可以使用方括号来使用这种语法:
<li *ngFor="#course of courses; #i = index" [id]="'someselector-'+i">{{course}}</li>
欲了解更多信息,请查看Pascal Precht的这篇有趣文章:http://blog.thoughtram.io/angular/2015/08/11/angular-2-template-syntax-demystified-part-1.html