Возможность доступа к Google Picker только время от времени. Всплывающее окно Google Picker открывается не каждый раз, когда я открываю приложение.
Я реализую Google Picker API в Angular 6. Я сохранил отдельный файл для логики подключения Google API в папке ресурсов angular и с помощью document.createElement ("script") добавил файл javascript. И у меня есть тег Anchor для getElementById в app.component.html.
app.component.html
<a routerLink="/" id="AllFilePick" #AllFilePick> Button </a>
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);
var s2 = document.createElement("script");
s2.src = "https://www.google.com/jsapi?key=<API_KEY>";
this.elementRef.nativeElement.appendChild(s2);
var s3 = document.createElement("script");
s3.src = "https://apis.google.com/js/client.js?onload=SetPicker";
this.elementRef.nativeElement.appendChild(s3);
// console.log(this.AllFilePick.nativeElement);
console.log(s1);
console.log(s2);
console.log(s3);
}
}
Я даже пробовал использовать ngAfterViewInit, конструктор для добавления тега скрипта.
assets / api-script.js
function SetPicker() {
var picker = new FilePicker(
{
apiKey: ‘<API_KEY>’,
clientId: ‘<CLIENT_ID>’,
buttonEl: document.getElementById("AllFilePick"),
onClick: function (file) {
PopupCenter('https://drive.google.com/file/d/' + file.id + '/view', "", 1026, 500);
}
}
);
}
function PopupCenter(url, title, w, h)
{
//.....
}
function FilePicker(User)
{
//Configuration
//....
}
Приведенный выше код полной версии работает правильно, но всплывающее окно открывается редко, время от времени. Всплывающее окно срабатывает только после обновления приложения несколько раз или открытия приложения на следующий день. Picker не работает регулярно в Angular.