简体   繁体   中英

string concatenation with property binding in angular2

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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