角UI $ scope.myMap是未定义 [英] Angular-UI $scope.myMap is undefined
问题描述
我试图 $观看
MYMAP
,但它永远不会触发。我已经把范围缩小到有使用 UI-IF
(如果我删除了UI-IF, $ scope.myMap
是正确的谷歌地图对象)。不过,我需要保持UI,如果为了获得 UI地图
来等待我的AJAX / DB查询来完成。
I'm trying to $watch
myMap
but it never fires. I've narrowed it down to having used ui-if
(if I remove the ui-if, $scope.myMap
is the proper google maps object). However I need to keep the ui-if in order to get ui-map
to wait for my AJAX/Db query to finish.
为什么不MYMAP被添加到范围(以及如何得到它)?
Plunker
修改我从看到这GitHub的问题的是用户界面,如果创建自己的范围。那么如何访问它的范围/无论 MYMAP
现在的生活?另外,为什么UI,如果创建一个新的范围是什么?
Edit I see from this GitHub issue that ui-if creates its own scope. So how do I access its scope / wherever myMap
now lives? Also, why does ui-if create a new scope?
推荐答案
您的GoogleMaps
控制器上创建一个模型:
Create a model on your GoogleMaps
controller:
$scope.model = {};
传递模型作为参考 UI地图
指令:
Pass the model as reference to the ui-map
directive:
ui-map="model.myMap"
观看更改:
$scope.$watch('model.myMap', function(map){
...
}
这样就避免了 MYMAP
属性的里面创建UI-IF
范围。
另外,请查阅此文档有关范围的原型继承的更多信息。
Also check this documentation for more information on the prototypical inheritance of scopes.
这篇关于角UI $ scope.myMap是未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!