【发布时间】:2017-03-31 17:45:35
【问题描述】:
在我的 Angular 2 应用程序中,我有一个函数:
notification : Array<any>;
......
......
getNotification () {
return setTimeout(() => {
this.AppbankService.notify(this.user.NameId)
.subscribe(
(response) => {
if (response.status === 200) {
this.notifications.push(response.json());
console.log(typeof(this.notifications));
}
this.getNotification();
}
)
},5000)}
在这个函数中,我每 5 秒收到一次来自服务器的通知,并尝试将它们推送到一个数组,但是有这个:
error app.module.ts:104 error : TypeError: Cannot read property 'push' of undefined(...)
有什么建议吗?
【问题讨论】: