![](/img/trans.png)
[英]ERROR TypeError: Cannot read properties of undefined (reading 'nativeElement')
[英]ERROR TypeError: Cannot read properties of undefined (reading 'nativeElement') while using datatable
我收到 ERROR TypeError: Cannot read properties of undefined (reading 'nativeElement') while using the datatable。
typescript
@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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.