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[] = [];
没有解决我 –