angular viewChild for dynamic elements inside ngFor

后端 未结 1 460
醉酒成梦
醉酒成梦 2020-12-30 23:22

My template has something like this:

is there a way

相关标签:
1条回答
  • 2020-12-30 23:50

    TL;DR Use ViewChildren instead of ViewChild

    As @Commerical Suicide mentioned you cannot set the references dynamically.

    The #div is called template reference variable.

    You can access your divs via ViewChildren in you *.ts file.

    Sample: @ViewChildren('div') divs: QueryList<ElementRef>

    Then you can call multiple methods on your new QueryList, like forEach or find.

    0 讨论(0)
提交回复
热议问题