如何解决“无法读取未定义的属性'dialogService'” Angular 9 gapi函数
我正在尝试打开一个对话框,其中包含从Google API客户端(gapi
)中检索到的数据。一切正常,直到我尝试将数据加载到对话框中。我收到的数据很好,我可以将数据传递到其他功能正常的对话框中,而没有问题,但是由于某些原因,我无法在gapi
函数中完成此操作。
我正在Angular框架中使用Nebular的NbDialog。这是我的代码:
import { Component,OnDestroy,OnInit,ElementRef } from '@angular/core';
import { FileListComponent } from '../../../pages/modal-overlays/dialog/file-list/file-list.component';
import { NbDialogService } from '@nebular/theme';
const gapi: any
@Component({
selector: 'ngx-header',styleUrls: ['./header.component.scss'],templateUrl: './header.component.html',})
export class HeaderComponent implements OnInit,OnDestroy {
constructor(private dialogService: NbDialogService){}
ngOnInit(){
//Initialize
gapi.load("client:auth2",() =>{
gapi.client.init({
apiKey: 'xxxxxxxxxxxxxxx',discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'],clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com',scope: 'profile https://www.googleapis.com/auth/drive.readonly'
}).then(function () {
// Listen for sign-in state changes.
// gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
if(gapi.auth2.getAuthInstance().isSignedIn.get()){
console.log('Sign-in successful');
gapi.client.drive.files.list({
pageSize: 100,corpora:'allDrives',fields: "nextPageToken,files(id,name)",includeItemsFromAllDrives:true,supportsAllDrives:true,q:"mimeType='application/vnd.google-apps.document'",}).then(function(res) {
// console.log returns data perfectly fine
console.log(res.result)
// below returns "Cannot read property 'dialogService' of undefined" even though I've used the
// EXACT same function outside this one with no issues
this.dialogService.open(FileListComponent,{
context: {
list: res.result.files,},});
});
}
else{
console.log('there was an error with sign-in my friend')
}
});
})
}
感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。