Angular Material表抛出未定义的nativeElement

问题描述

我试图在Angular 8中使用非常基本的Material表。该组件无法呈现,并且在控制台日志中发现以下异常:

错误错误:未捕获(承诺):TypeError:无法读取未定义的属性'nativeElement'

这似乎是一个常见错误。有没有人设法解决这个问题?

https://github.com/angular/components/issues/9813

解决方法

将tsconfig.json中的目标属性更新为es5

  "compilerOptions": 
    {
 "sourceMap": true,"declaration": false,"moduleResolution": "node","emitDecoratorMetadata": true,"experimentalDecorators": true,"target": "es5","typeRoots": [ "node_modules/@types" ],"lib": [ "es2017","dom" ] 
    }