简体   繁体   English

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

[英]string concatenation with property binding in angular2

in Angular 2 we have several way to create property bindings in templates. 在Angular 2中,我们有几种方法可以在模板中创建属性绑定。 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? 是否可以使用方形brakets语法获得相同的结果?

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

Thanks, G. 谢谢,G。

I found out that you can use this kind of syntax using square brackets: 我发现你可以使用方括号来使用这种语法:

<li *ngFor="#course of courses; #i = index" [id]="'someselector-'+i">{{course}}</li>

For more information, please have a look to this interesting article from Pascal Precht: http://blog.thoughtram.io/angular/2015/08/11/angular-2-template-syntax-demystified-part-1.html 欲了解更多信息,请查看Pascal Precht的这篇有趣文章: http//blog.thoughtram.io/angular/2015/08/11/angular-2-template-syntax-demystified-part-1.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM