如何解决没有初始值设定项且未在构造函数中明确分配'x'打字稿错误?



报错

Property 'duni' has no initializer and is not definitely assigned in the constructor.ts(2564)

下一行
@ViewChild('bhondu') duni: ElementRef<HTMLTableDataCellElement>;

使它可选使用?打破代码在其他地方,我使用this.duni.nativeElementObject is possibly 'undefined'.ts(2532)。我如何解决这个错误不改变配置文件中的任何属性

?

使用非空断言操作符

@ViewChild('bhondu') duni!: ElementRef<HTMLTableDataCellElement>;

相关内容

最新更新