3
财产“推”在我的角2应用程序,我有一个函数:角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秒,并试图将它们推到一个数组,但有一个:错误app.module.ts:104错误:TypeError:无法读取属性'推'的undefined(...)
任何建议吗?
thx它适合我,但你能告诉我为什么我必须这样做吗?类型不够? –
不,类型只指定可以在此属性中存储哪种类型的值,但它不具有值。用'= []'我们用一个有'.push()'方法的空数组初始化它。 –
适合我..大 –