Nirmesh
Nirmesh

Reputation: 305

How to set id in angular2 dynamically

Is there anyway we can set id conditionally in angular2. Lets say I have a component template.

<span id="setTextId()"> 

I want to set my id return by this setTextId() function how can i do that?

Upvotes: 1

Views: 3269

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 19622

span [id]="setTextId()"

In Component the method will be

id : number = 0;

setTextId(){
  this.id++
}

Upvotes: 3

Related Questions