javascript - 为 Angular 项目包装 google-closure-library 变量
问题描述
所以,从这个问题开始
我现在在 bower 和 npm 中都有我的模块,我可以将它很好地导入我的项目并在 app.module 中声明它,甚至尝试在我的控制器中使用它:
索引.html:
<script src="bower_components/google-closure-library/closure/goog/base.js"></script>
app.module.js:
angular
.module('drugQualityDataManagerApp', [
'ngStorage',
'ngResource',
'ngCookies',
'ngAria',
'web-gl-earth2',
上传数据.controller.js:
$scope.initializeMapWebGL = function(){
var earth = new webGlEarth.map('earth_div');
webGlEarth.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(earth);
var marker = webGlEarth.marker([51.5, -0.09]).addTo(earth);
marker.bindPopup("<b>Hello world!</b><br>I am a popup.<br /><span style='font-size:10px;color:#999'>Tip: Another popup is hidden in Cairo..</span>", {maxWidth: 150, closeButton: true}).openPopup();
var marker2 = webGlEarth.marker([30.058056, 31.228889]).addTo(earth);
marker2.bindPopup("<b>Cairo</b><br>Yay, you found me!", {maxWidth: 120, closeButton: false});
var markerCustom = webGlEarth.marker([50, -9], '/img/logo-webglearth-white-100.png', 100, 24).addTo(earth);
earth.setView([51.505, 0], 6);
};
上传数据.html:
<style>
html, body{padding: 0; margin: 0; background-color: black;}
#earth_div{top: 0; right: 0; bottom: 0; left: 0; position: absolute !important;}
</style>
<title>WebGL Earth API: Markers</title>
<body onload="initialize()">
<div id="earth_div"></div>
</body>
但是,当然,这不会那么直截了当,问题来自 webgearth2 的依赖项,这个应用程序强烈依赖于 google-closure-library,而 angular 不喜欢这样,我尝试过包装main.js 文件,如:
(function () {
'use strict';
angular.module('web-gl-earth2', []).provider('webGlEarth');
我将 google-closure-library 添加到我的 bower_components 和 app.module.js 中,但我仍然感到害怕:
Uncaught ReferenceError: goog is not defined
所以,我留下了一个问题:是否有一个自动包装器可以帮助我将这个模块集成到 Angular 中,还是我注定要重新编写整个源代码以使其“有角度的可爱”?
解决方案
推荐阅读
- javascript - 包含脚本
- python - CreateView 在提交时不保存,但在 UpdateView 上
- flutter - ScanStreamTransformer 上的 NULL 累加器
- javascript - JavaScript / Mocha - 如何测试是否等待函数调用
- java - 使用 with* 函数、TemporalAdjusters 或设置 TemporalFields 调整 ZonedDateTimes 之间有什么区别吗?
- php - 在 docker-compose 中使用 PhpStorm/Idea 和 Symfony 进行 Xdebug:仅在第一个文件 index_dev.php 处中断
- r - r 包文档中的方程式不起作用
- php - PHP 在 JS 中改变值
- php - 如何在 Google API PHP 客户端 2.2.2 版中设置 curl 超时
- excel - Google 日历导出和 getName() 的问题