angular @ViewChild和@ViewChildren的使用
@ViewChild和@ViewChildren都是模板变量,前者是单一的,后者是以数组的形式存储
用法
1、在需要使用的标签上用#变量名标识一个标签
<div id="report" #report>
<div #reportContainer id="item">
</div>
</div>
2、在TS文件中定义
@ViewChild('report') report:any | undefined
3、使用
获取子元素的个数 this.report.valueOf().nativeElement.childNodes.length
获取子元素中的数据 this.report.valueOf().nativeElement.childNodes[1].__ngContext__[30].title

浙公网安备 33010602011771号