我得到错误类型错误:在使用数据表时无法读取未定义的属性(读取"nativeElement"(。
打字文字
@ViewChild('dataTable',{static:false}) table;
ngAfterViewInit(): void {
// if (!this.table) return;
this.dataTable=$(this.table.nativeElement);
this.dataTable.DataTable();
console.log( this.dataTable.DataTable());
}
HTML
<table #dataTable id="example" class="table table-striped table-bordered" style="width:100%">
</table>
@ViewChild('dataTable',{static:false}) table : ElementRef;
ngAfterViewInit(): void {
// if (!this.table) return;
this.dataTable=$(this.table.nativeElement);
this.dataTable.DataTable();
console.log( this.dataTable.DataTable());
}
或者您可以使用@ViewChild('dataTable',{static:false}(table:any;