更新时间: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>;