繁体   English   中英

错误类型错误:使用数据表时无法读取未定义的属性(读取“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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM