首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >method().bind(this) + Angular4 getting无法读取未定义的属性“”myFun“”

method().bind(this) + Angular4 getting无法读取未定义的属性“”myFun“”
EN

Stack Overflow用户
提问于 2018-01-03 01:53:20
回答 1查看 101关注 0票数 0

我将Google picker API集成到我的应用程序中。我正在遵循官方文档Google Picker API

我已经成功地完成了我的工作,但是在添加了下面的代码之后,我无法使用类方法和变量。获取无法读取未定义错误的属性

代码语言:javascript
复制
gapi.load('auth', {'callback': this.onAuthApiLoad.bind(a)});

完整的代码是:

代码语言:javascript
复制
onApiLoad() {
    var a= this;
    gapi.load('auth', {'callback': this.onAuthApiLoad.bind(a)});
    gapi.load('picker');
  }

  onAuthApiLoad() {
    gapi.auth.authorize(
        {
          'client_id': this.clientId,
          'scope': this.scope,
          'immediate': false
        },
        this.handleAuthResult);
  }

  handleAuthResult(authResult) {
    if (authResult && !authResult.error) {
      if (authResult.access_token) {
        var pickerBuilder = new google.picker.PickerBuilder();
        var picker = pickerBuilder.
            enableFeature(google.picker.Feature.NAV_HIDDEN).
            setOAuthToken(authResult.access_token).
            addView(google.picker.ViewId.DOCS).
            setCallback(this.myFun).
            build();
        picker.setVisible(true);
      }
    }
  }

  myFun(e){

}
EN

回答 1

Stack Overflow用户

发布于 2018-01-03 02:01:51

我添加了以下行来处理身份验证请求

代码语言:javascript
复制
this.handleAuthResult.bind(this)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48065586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档