鍍金池/ 問答/HTML5  HTML/ ionic3 報錯: TypeError: XXX is not a funct

ionic3 報錯: TypeError: XXX is not a function

貌似又是一個初級錯誤,問題出哪了?

報錯:Error: Uncaught (in promise): TypeError: _this.rest.getUserInfo is not a function

1.報錯截圖:
圖片描述

2.this.rest.getUserInfo 代碼行片斷:
圖片描述

3.公共 getUserInfo 方法:
圖片描述

======================================
loadUserPage方法源碼:

  public notLogin: boolean = true;
  public logined: boolean = false;
  headface: string;
  userinfo: string[];
  loadUserPage() {
    this.Storage.get('UserId').then((val) => {
      if (val != null) {
        //加載用戶數(shù)據(jù)
        var loading = super.showLoading(this.loadCtrl, "加載中..."); 
        this.rest.getUserInfo(val)
          .subscribe(
          userinfo => {
            this.userinfo = userinfo;
            this.headface = userinfo["UserHeadface"] + "?" + (new Date()).valueOf();
            this.notLogin = false;
            this.logined = true;
            loading.dismiss();
          }
          );
      }
      else {
        this.notLogin = true;
        this.logined = false;
      }
    });
  }
回答
編輯回答
糖豆豆

很顯然,你取不到正確的 getUserInfo 地址。檢查一下 this 指向。如果在回調(diào)里面用最好用箭頭函數(shù)。

2017年1月28日 09:02