小编Aru*_*ish的帖子

Angular 6 - Google Picker API 弹出窗口

只能偶尔访问 Google Picker。每次打开应用程序时,Google Picker Popup 都不会打开。

我正在 Angular 6 中实现 Google Picker API。我在 angular 的资产文件夹中为连接 Google API 背后的逻辑保留了单独的文件,并在 document.createElement("script") 的帮助下附加了 javascript 文件。我在 app.component.html 中有一个指向 getElementById 的 Anchor 标记。

应用程序组件.html

<a routerLink="/" id="AllFilePick" #AllFilePick> Button </a>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

    import { Component, ViewChild, ElementRef, OnInit } from '@angular/core';


    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss']
    })


    export class AppComponent implements OnInit {

      @ViewChild('AllFilePick') AllFilePick: ElementRef;

      constructor(private elementRef: ElementRef) { }


      ngOnInit() { 

        var s1 = document.createElement("script");
        s1.type = "text/javascript";
        s1.src = "../assets/api-script.js";
        this.elementRef.nativeElement.appendChild(s1); …
Run Code Online (Sandbox Code Playgroud)

javascript google-api typescript google-picker angular

4
推荐指数
2
解决办法
2426
查看次数