3

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);
        });
    });
}
Milo
  • 3,365
  • 9
  • 30
  • 44
Josh Walker
  • 51
  • 2
  • 4
  • 1
    http://stackoverflow.com/questions/40510795/cannot-call-a-function-on-an-element-inside-ngfor-angular2/40511035#40511035 – silentsod Nov 09 '16 at 18:39

2 Answers2

10

Try to bypass the error with:

this._notifications = data['notifications'];
Avram Virgil
  • 1,170
  • 11
  • 22
0

Try another way to bypass the error with:

return new Promise().then(()=>{
     return data;
})
Bugs
  • 4,491
  • 9
  • 32
  • 41
bignewyork
  • 23
  • 7