Angularjs等到
发布时间:2020-12-17 17:48:38 所属栏目:安全 来源:网络整理
导读:我有: $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 = {} 后来在我的代码中: $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(…). 所以我需要“等到边界设置”之类的东西. 解决方法
您可以将$watch用于此目的,如下所示:
$scope.$on('leafletDirectiveMap.load',function(){ $scope.$watch( "bounds",function(n,o){ if(n==o) return; Dajaxice.async.hello($scope.populate,{ 'west' : $scope.bounds.southWest.lng,}); },true); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |