【问题标题】:Gapi.iframes does not work since Angular 2自 Angular 2 以来,Gapi.iframes 不起作用
【发布时间】:2018-09-21 14:53:47
【问题描述】:

自 Angular 2 以来,ng-gapi 出现问题。我需要显示谷歌“托管配置 iframe”,我按照Google developper doc 中的步骤操作,它适用于 angularJS,但是当我使用 Angular 2+ 进行尝试时它没有。

this.gapiService.onLoad().subscribe((result:any)=> {
        gapi.load("gapi.iframes", function(){           

            var iframeContainer = document.getElementById('iframecontainer');

            var context = gapi.iframes.getContext();

            var options = {
              'url': this.url,
              'where': iframeContainer,
              'attributes': { 
                style: 'height:1200px', 
                scrolling: 'yes'
              }
            }

            var iframe = context.openChild(options);

            iframe.register('onconfigupdated', function(o) {
                console.log(o);
                this.data.mcmId = o.mcmId;                    
                this.dialogRef.close(this.data);
            } , function(data) { 
                return true; 
            });

            iframe.register('onconfigdeleted', function(o) {
                console.log(o);
                this.data.mcmId = null;                    
                this.dialogRef.close(this.data);
            } , function(data) { 

                return true; 

            });


        });
    });

问题是我认为 GAPI 中不存在 iframe,我需要使用 Gapi 渲染 iframe 以捕获“onconfigupdated”和“onconfigdeleted”事件。

【问题讨论】:

    标签: javascript angular iframe google-api-js-client


    【解决方案1】:

    所以如果你不使用gapi JS库,预计你不会收到来自iframe的事件,你需要使用gapi JS库才能接收事件。

    如果 ng-gapi 包装器不支持 iframe,那么您可以扩展它以支持 iframe,或者专门为您的用例创建自己的自定义包装器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-07
      • 2016-12-18
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-16
      • 2017-09-01
      相关资源
      最近更新 更多