该数组包含至少 10 个对象
array: any[] = [];
调用函数时,数组应包含“item”中的现有对象和新对象。
function () {
var timeline = this.service.fetchservice(10)
.map((result : Response) => result.json())
.subscribe(item=> {
this.array.push(item);
});
}
控制台出错
ERROR TypeError: _this.array.push is not a function
类似:
this.results = this.results.concat(data.results);
使用
function()
时,它采用函数本身的上下文。您应该使用 Typescript 类方法,例如:
export class TestApp {
someMethod(): void {
// does something
}
}