Give dynamic id Angular2 Binds

the way you said works, Angular 2.0.0.beta.8.

in this case you can use for example:

  • [id]="item.id"
  • [attr.id]="item.id"
  • id={{item.id}}

         <ul>
          <li *ngFor="#item of items" #elem [id]="item.id">
            {{ item.name}} ID: {{elem.id}}
          </li>
         </ul>
    
         <ul>
          <li *ngFor="#item of items" #elem [attr.id]="item.id">
            {{ item.name}} ID: {{elem.id}}
          </li>
         </ul>
    
         <ul>
          <li *ngFor="#item of items" #elem id={{item.id}}>
            {{ item.name}} ID: {{elem.id}}
          </li>
         </ul>
    

Plunker

You can look here for more information in Template syntax.

https://angular.io/guide/cheatsheet

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)