TypeScript:无法读取 [null] 中未定义的属性“push" [英] TypeScript: Cannot read property 'push' of undefined in [null]
本文介绍了TypeScript:无法读取 [null] 中未定义的属性“push"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误:无法读取 [null] 中未定义的属性push".
class A implements OnInit {
stringArr: string[];
ngOnInit() {
for(let i=0; i<4; i++) {
this.stringArr.push("aaa");
}
}
}
推荐答案
数组需要初始化:
stringArr = [];
这篇关于TypeScript:无法读取 [null] 中未定义的属性“push"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文