0
如何初始化一個空數組?angular2和Typescript數組 - 屬性'push'不存在於類型'()=> void'
test: any[];
//On change I want to add an item to an array
test(){
this.test.push('a');
}
錯誤TS2339:屬性 '推' 類型上不存在 '()=>無效'。
如何初始化一個空數組?angular2和Typescript數組 - 屬性'push'不存在於類型'()=> void'
test: any[];
//On change I want to add an item to an array
test(){
this.test.push('a');
}
錯誤TS2339:屬性 '推' 類型上不存在 '()=>無效'。
您不初始化您的陣列,所以test
是undefined
。爲了能夠使用它,只需以這種方式初始化它:
test: any[] = [];
沒有解決我 –