Reputation: 51
I'm using Ionic and Angular2 Typescript. When View is rendered I call the function retrieveNotifications
in the file dashboard.ts but I get an error:
Error: Error at /home/invicta/Desktop/newauth/.tmp/pages/dashboard/dashboard.ts:36:34 Property 'notifications' does not exist on type '{}'
//dashboard.ts
ionViewDidEnter() {
this.retrieveNotifications();
}
retrieveNotifications() {
this.user.retrieveNotifications().then(data = > {
// when do console.log here and typeof(), data is object and it has notifications array
this._notifications = data.notifications;
})
}
Then in file user-data.ts which is declare like public user: UserData
is function:
//user-data.ts -> provider
retrieveNotifications() {
var token = this.authservice.getUserToken();
return new Promise(resolve = > {
var headers = new Headers();
headers.append('Authorization', 'Bearer ' + token);
this.http.get(this.mainUrl + '/api/v1/notification', {
headers: headers
}).subscribe(data = > {
if (data.status === 200)
resolve(data.json());
else
resolve(false);
});
});
}
Upvotes: 3
Views: 4141
Reputation: 23
Try another way to bypass the error with:
return new Promise().then(()=>{
return data;
})
Upvotes: 0
Reputation: 1210
Try to bypass the error with:
this._notifications = data['notifications'];
Upvotes: 10