且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用动态参考angular2传递元素?

更新时间:2023-11-26 16:32:28

* ngFor 中可以使用相同的模板变量名称,无需在 * ngFor 中创建唯一的模板变量名称。

It is okay to have same template variable name inside *ngFor, no need to make unique template variable name inside *ngFor.

Html

<div *ngFor="let floor of floors">
  <button #fb (click)="onClick(fb)"></button>
</div>

即使拥有类似的模板名称,也可以使用 @ViewChildren查询DOM decorator。

Even by having similar template name, you can query the DOM using @ViewChildren decorator.

@ViewChildren('fb') fbButtons:QueryList<any>;