wsuite-ng-gapi
Version:
Angular 7+ Google api module ng-gapi
51 lines (50 loc) • 2.34 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
import { Observable } from "rxjs/Observable";
import { Inject, Injectable, InjectionToken } from "@angular/core";
import { GoogleApiConfig } from "./config/GoogleApiConfig";
export var NG_GAPI_CONFIG = new InjectionToken("ng-gapi.config");
var GoogleApiService = /** @class */ (function () {
function GoogleApiService(config) {
this.gapiUrl = 'https://apis.google.com/js/api.js';
this.config = new GoogleApiConfig(config);
this.loadGapi().subscribe();
}
GoogleApiService.prototype.onLoad = function () {
return this.loadGapi();
};
GoogleApiService.prototype.getConfig = function () {
return this.config;
};
GoogleApiService.prototype.loadGapi = function () {
var _this = this;
return new Observable(function (observer) {
var node = document.createElement('script');
node.src = _this.gapiUrl;
node.type = 'text/javascript';
node.charset = 'utf-8';
document.getElementsByTagName('head')[0].appendChild(node);
node.onload = function () {
observer.next(true);
observer.complete();
};
});
};
GoogleApiService = __decorate([
Injectable(),
__param(0, Inject(NG_GAPI_CONFIG)),
__metadata("design:paramtypes", [Object])
], GoogleApiService);
return GoogleApiService;
}());
export { GoogleApiService };