In my Angular 2 application I have a function :
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)}
In this function, I get notification from the server every 5 seconds and try to push them to an array, but a have this:
error app.module.ts:104 error : TypeError: Cannot read property 'push' of undefined(…)
Any suggestion?