加载文件js offline(本地node_modules)

时间:2018-04-12 14:12:32

标签: angular node-modules

我已经安装了ng2-google-charts,但是在https://www.gstatic.com/charts/loader.js上传了loader.js。如何更改为LOCAL?

我尝试更改文件/home/kleber/angular/escola/node_modules/ng2-google-charts/google-charts-loader.service.js

    GoogleChartsLoaderService.prototype.loadGoogleChartsScript = function () {
            var _this = this;
            return new Promise(function (resolve, reject) {
                if (resolve === void 0) { resolve = Function.prototype; }
                if (reject === void 0) { reject = Function.prototype; }
                if (typeof google !== 'undefined' && google.charts) {
                    resolve();
                }
                else if (!_this.googleScriptIsLoading) {
                    _this.googleScriptIsLoading = true;
                    var script = document.createElement('script');
                    script.type = 'text/javascript';
<-----------------------------------HERE ------------------>
                    //script.src = 'https://www.gstatic.com/charts/loader.js';
                    script.src = './loader.js';
<-----------------------------------HERE ------------------>
                    script.async = true;
                    script.defer = true;
                    script.onload = function () {
                        _this.googleScriptIsLoading = false;
                        _this.googleScriptLoadingNotifier.emit(true);
                        resolve();
                    };
                    script.onerror = function () {
                        _this.googleScriptIsLoading = false;
                        _this.googleScriptLoadingNotifier.emit(false);
                        reject();
                    };
                    document.getElementsByTagName('head')[0].appendChild(script);
                }
                else {
                    _this.googleScriptLoadingNotifier.subscribe(function (loaded) {
                        if (loaded) {
                            resolve();
                        }
                        else {
                            reject();
                        }
                    });
                }
            });
        };

Error console

1 个答案:

答案 0 :(得分:1)

我搜索过,但没有找到离线js。 Google服务条款不允许您下载google.charts.load或google.visualization代码以便离线使用。

https://developers.google.com/chart/interactive/faq