这是我的以下代码:
private convertFormat(src: Array<any>): void {
for (let i of src) {
this.selectedMonths.push({
id: i,
itemName: i
})
};
this.selectedMonths = JSON.parse(JSON.stringify(this.selectedMonths));
console.log(this.selectedMonths);
}
但是,当我尝试插入已声明的数组 <{}> 时,“.push()
”会出现此错误。
Unhandled Promise rejection: Cannot read property 'push' of undefined ; Zone: ; Task: Promise.then ; Value: TypeError: Cannot read property 'push' of undefined
最佳答案
selectedMonths : any[] = []
在组件类或 ngOnInit this.selectedMonths = [];
关于javascript - 未处理的 Promise 拒绝 : Cannot read property 'push' of undefined Value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47442094/