Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string concatenation with property binding in angular2

Tags:

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.

like image 784
gabric Avatar asked Apr 07 '16 10:04

gabric


People also ask

What are the 2 methods used for string concatenation?

There are two ways to concatenate strings in Java: By + (String concatenation) operator. By concat() method.

What is Property binding in Angularjs?

Property binding in Angular helps you set values for properties of HTML elements or directives. Use property binding to do things such as toggle button features, set paths programmatically, and share values between components.

Which is an example of string concatenation?

In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball".

What happens when you concatenate two strings in .NET framework?

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.


1 Answers

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

like image 174
gabric Avatar answered Sep 28 '22 00:09

gabric