指令模板 -
<li *ngFor = "#el of dragZoneElems; #idx = index">
<h4 [style.position]="'fixed'" [style.top.px]="idx* 30" [style.margin-top] = "80.0" [style.z-index] = 100 [dragResponder] = "el">{{el.first}} {{el.last}}</h4>
</li>
我需要使用指令类中的对象值来访问创建的h4元素。我该怎么做。
答案 0 :(得分:1)
不确定“访问”是什么意思,但我认为这是你想要的:
<li *ngFor = "#el of dragZoneElems; #idx = index">
<!-- added: #h4 -->
<h4 #h4 [style.position]="'fixed'" [style.top.px]="idx* 30" [style.margin-top] = "80.0" [style.z-index] = 100 [dragResponder] = "el">{{el.first}} {{el.last}}</h4>
</li>
class MyComponent {
@ViewChildren('h4') h4s;
ngAfterViewInit() {
console.log(this.h4s.length);
}
}