小编Jos*_*ker的帖子

在Typescript中的Object类型中不存在属性

所以我使用Ionic和Angular2 Typescript.当呈现View时,我retrieveNotifications在文件中调用函数,dashboard.ts但是我收到错误:

Error: Error at /home/invicta/Desktop/newauth/.tmp/pages/dashboard/dashboard.ts:36:34 
Property 'notifications' does not exist on type '{}'
Run Code Online (Sandbox Code Playgroud)

这里还有一个截图:https://www.dropbox.com/s/6x2myxqm2q4dhzb/Screenshot%202016-11-09%2019.29.52.png?dl=0


//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;
  })
}
Run Code Online (Sandbox Code Playgroud)

然后在文件user-data.ts中声明为public user:UserData是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: …
Run Code Online (Sandbox Code Playgroud)

promise typescript ionic2 angular

3
推荐指数
1
解决办法
3345
查看次数

标签 统计

angular ×1

ionic2 ×1

promise ×1

typescript ×1