字符串连接与angular2中的属性绑定

gab*_*ric 21 javascript angular2-template

在Angular 2中,我们有几种方法可以在模板中创建属性绑定.我可以这样做:

<li *ngFor="#course of courses; #i = index" id="someselector-{{i}}">{{course}}</li>
Run Code Online (Sandbox Code Playgroud)

是否可以使用方形brakets语法获得相同的结果?

<li *ngFor="#course of courses; #i = index" [id]="someselector-i">{{course}}</li>
                                            ^^^^^^^
                                  how create string concatenation?
Run Code Online (Sandbox Code Playgroud)

谢谢,G.

gab*_*ric 48

我发现你可以使用方括号来使用这种语法:

<li *ngFor="#course of courses; #i = index" [id]="'someselector-'+i">{{course}}</li>
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请查看Pascal Precht的这篇有趣文章:http://blog.thoughtram.io/angular/2015/08/11/angular-2-template-syntax-demystified-part-1.html