Javascript angular2 中与属性绑定的字符串连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36473418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
string concatenation with property binding in angular2
提问by gabric
in Angular 2 we have several way to create property bindings in templates. I could do something like this:
在 Angular 2 中,我们有几种方法可以在模板中创建属性绑定。我可以做这样的事情:
<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.
谢谢,G。
回答by gabric
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