我有:
作为你的助手,我可以翻译以下内容。这是一个关于编程的问题。
$scope.bounds = {}
以后在我的代码中:
$scope.$on('leafletDirectiveMap.load', function(){
console.log('runs');
Dajaxice.async.hello($scope.populate, {
'west' : $scope.bounds.southWest.lng,
'east': $scope.bounds.northEast.lng,
'north' : $scope.bounds.northEast.lat,
'south': $scope.bounds.southWest.lat,
});
});
作为你的助手,我可以翻译以下内容。这是一个关于编程的问题。
如您所见,在开始时边界是空的,但稍后(几毫秒)用 JavaScript 库(leaflet angular)加载。然而,$scope.$on(...)
在边界设置之前运行,因此 'west' : $scope.bounds.southWest.lng,
返回未定义变量的错误。
我想做的是等待边界(southWest
和 northEast
)被设置,然后运行 Dajaxice.async.hello(...)
。
所以我需要像“等待边界设置”这样的东西。
$scope.bound = {};
缺少一个 's',所以$scope.bounds.
不存在,因此未定义。或者,您应该使用$scope.$watch('bounds',function(newVal,oldVal){ .. stuff here ..})
来查看变量是否已更改并加载您想要的内容。 - m.e.conroy