[英]method().bind(this) + Angular4 getting Cannot read property 'myFun' of undefined
I'm integrating Google picker API in my application. 我正在将Google Picker API集成到我的应用程序中。 I'm following the official documentation Google Picker API
我正在使用Google Picker API的官方文档
I have successfully done my job, but after adding below code I am unable to use class methods and variables. 我已经成功完成了工作,但是在添加下面的代码后,我无法使用类方法和变量。 Getting Cannot read property of undefined error
获取无法读取未定义错误的属性
gapi.load('auth', {'callback': this.onAuthApiLoad.bind(a)});
Complete code is: 完整的代码是:
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){
}
我在下面添加了行以处理身份验证请求
this.handleAuthResult.bind(this)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.