[英]method().bind(this) + Angular4 getting Cannot read property 'myFun' of undefined
我正在將Google Picker API集成到我的應用程序中。 我正在使用Google Picker API的官方文檔
我已經成功完成了工作,但是在添加下面的代碼后,我無法使用類方法和變量。 獲取無法讀取未定義錯誤的屬性
gapi.load('auth', {'callback': this.onAuthApiLoad.bind(a)});
完整的代碼是:
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.