How to set unique template reference variables inside an *ngFor? (Angular)

后端 未结 3 1035
小鲜肉
小鲜肉 2020-12-05 14:25

I have a bunch of input fields in a *ngFor loop. The documentation says that template reference variables should be unique. Is there a way to do something like

3条回答
  •  难免孤独
    2020-12-05 15:05

    Template variables need to be unique with respect to the template rather than the rendering of the template (the actual values). You want to use ViewChildren.

    @ViewChildren('attendee') attendeeInputs: QueryList;
    

    You can treat attendeeInputs as a QueryList and operate on each attendee input individually as needed based on iteration of the indices.

提交回复
热议问题