可以通过以下两种方法来解决此问题:
const myObj = document.querySelector('#myElement')!;
const myObj = document.querySelector('#myElement');
if (myObj) {
// 处理非null情况
}
上一篇:Angular报错core.js:35929 Uncaught TypeError: Cannot read property 'id' of undefined的错误信息。
下一篇:Angular报错TypeError:Youprovided'undefined'whereastreamwasexpected