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) {
        //加载用户数据
        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;
      }
    });
  }
阅读 4.7k
1 个回答

很显然,你取不到正确的 getUserInfo 地址。检查一下 this 指向。如果在回调里面用最好用箭头函数。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进