我有一個mainController.js對象被設置爲默認爲99如何使HTML等待在AngularJS控制器的功能
我獲取用戶的位置和運行做一些其他的功能,用它來計算這個值。
但是,當我加載頁面時,頁面似乎加載比這個過程更快。因此它顯示99而不是計算值。 如果我在計算之後放置console.log,則該對象已成功更改。
EDIT1:
status.success(function(data)
{
$scope.current = data;
$scope.$broadcast('back_end_connected');
});
$scope.getLocation = function()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function (position){
$scope.location = {lat: position.coords.latitude, lng: position.coords.longitude};
$scope.$broadcast('location_obtained');
$scope.buildDist();
$scope.fetch();
//$scope.getRec();
});
}
else{
alert("Geolocation is not supported by this browser.");
}
};
var dirBuilt = false;
$scope.$on('location_obtained', function(){
$scope.buildDist = function()
{
if(dirBuilt === false)
{
$scope.facilities[0].distance = distCalc($scope.location.lat,$scope.location.lng,$scope.facilities[0].location.lat,$scope.facilities[0].location.lng);
$scope.facilities[1].distance = distCalc($scope.location.lat,$scope.location.lng,$scope.facilities[1].location.lat,$scope.facilities[1].location.lng);
$scope.facilities[2].distance = distCalc($scope.location.lat,$scope.location.lng,$scope.facilities[2].location.lat,$scope.facilities[2].location.lng);
$scope.facilities[3].distance = distCalc($scope.location.lat,$scope.location.lng,$scope.facilities[3].location.lat,$scope.facilities[3].location.lng);
$scope.facilities[4].distance = distCalc($scope.location.lat,$scope.location.lng,$scope.facilities[4].location.lat,$scope.facilities[4].location.lng);
$scope.facilities[5].distance = distCalc($scope.location.lat,$scope.location.lng,$scope.facilities[5].location.lat,$scope.facilities[5].location.lng);
$scope.$broadcast('dist_obtained');
dirBuilt = true;
alert("aaa: "+ $scope.facilities[0].distance);
}
};
});
認爲 「警報(」 AAA: 「+ $ scope.facilities [0] .distance);」返回我希望它顯示的值,但它不顯示在頁面上...... (ng-bind不會出於某種原因...)
如何使html等待操作?謝謝
好,如果我有一個像 {PLACEHOLD: 「裝載」,值:99} 最初顯示placeHold ,,, 我怎麼知道什麼時候加載並交換值? –
'value:'loading''並更新後的值與實際值? –
但是,它仍然會顯示「加載」,即使當它完成加載像現在... –