使用UI路由器的决心,等待谷歌地图加载 [英] Using a ui-router resolve to wait for a google map to load
问题描述
我试图加载仪表盘状态之前加载谷歌地图。似乎像一个UI路由器决心完美的使用
。
不幸的是, uiGmapIsReady
的承诺是永远不会解决。
任何帮助将大大AP preciated。
状态('app.dashboard',{
网址:'/仪表盘,
templateUrl:'谐音/ dashboard.html',
控制器:'dashCtrl',
数据:{
authorizedRoles:[USER_ROLES.all]
},
解析:{
getGoogleMap:功能(地图服务){ 返回MapService.getMap();
}
}
}).factory('的MapService',函数(uiGmapIsReady,$ Q){ 变种物镜= {}; //返回一个只解决了后角谷歌,地图创建的谷歌地图对象加载一个承诺
obj.getMap =功能(){ 变种推迟= $ q.defer(); uiGmapIsReady.promise()
。然后(功能(图){
deferred.resolve(图[0] .MAP);
}); 返回deferred.promise; };返回OBJ;
这在等待的决心控制器还用于建立由角谷歌 - 地图绘制地图所需变量的作用域控制器。导致此:解决导致控制器不会被调用 - >地图永远不会被绘制,因为它正在等待控制器上设定一些范围的对象 - >解决正在等待永远不会被绘制的地图触发器 - >控制器从未被调用
I'm trying to load a google map before loading the dashboard state. Seems like the perfect use for a ui-router resolve
.
Unfortunately, the uiGmapIsReady
promise is never resolving.
Any help would be greatly appreciated.
state('app.dashboard', {
url: '/dashboard',
templateUrl: 'partials/dashboard.html',
controller: 'dashCtrl',
data: {
authorizedRoles: [USER_ROLES.all]
},
resolve: {
getGoogleMap: function(MapService){
return MapService.getMap();
}
}
})
.factory('MapService', function(uiGmapIsReady, $q) {
var obj = {};
//returns a promise that is resolved only after the google map object created by angular-google-maps is loaded
obj.getMap = function(){
var deferred = $q.defer();
uiGmapIsReady.promise()
.then(function(map){
deferred.resolve(map[0].map);
});
return deferred.promise;
};
return obj;
The controller that was waiting on the resolve was also the controller that establishes the scope variables needed by angular-google-maps to draw the map. That caused this: resolve cause the controller to not get called --> map never gets drawn because it is waiting on the controller to set some scope objects--> resolve that is waiting for map to be drawn never triggers --> controller never gets called
这篇关于使用UI路由器的决心,等待谷歌地图加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!