Give dynamic id Angular2 Binds

后端 未结 4 2084
时光说笑
时光说笑 2021-02-05 03:11

My JavaScript:

 this.items = [
            {name: \'Amsterdam1\', id: \'1\'},
            {name: \'Amsterdam2\', id: \'2\'},
            {name: \'Amsterdam3\', i         


        
4条回答
  •  忘了有多久
    2021-02-05 03:41

    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}}

           
      • {{ item.name}} ID: {{elem.id}}
      • {{ item.name}} ID: {{elem.id}}
      • {{ item.name}} ID: {{elem.id}}

    Plunker

    You can look here for more information in Template syntax.

    https://angular.io/guide/cheatsheet

提交回复
热议问题