2017-11-22 3 views
0

의 특성 '푸시'를 읽을 수 없습니다이 내 다음 코드 :처리되지 않은 약속 제거 : 정의되지 않은 값

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

+2

'selectedMonths는 : 어떤은 [] = []'구성 요소 클래스 또는'에서 ngOnInit'는'this.selectedMonths = [];' – DrNio

+0

나는 볼 수 없습니다 당신의 전체 코드를 시도 할 수 있지만이 시도 할 수 있습니다 : private convertFormat = (src : Array ) : void => {{}} 'this'가 클래스 인스턴스가 아닐 수도 있습니다. – Daniel

+0

@ Z.Bagley "Array <{}>" – ezzzCash

답변

1

selectedMonths : any[] = [] 또는 ngOnInit this.selectedMonths = [];

관련 문제