1
votes

I want that other controllers should wait for a controller to execute -as an important update (on which other controllers are dependent) occurs there.

This is as follows:`app.controller('locCtrl',function($rootScope,$scope){

$scope.change = function(){
$rootScope.userLocUrl="api.openweathermap.org/data/2.5/weather?q="+$scope.city+","+$scope.country;
$rootScope.flag="y";
};

$scope.showU = function(){
return $rootScope.userLocUrl;
};   

});`

The value of $rootScope variable - "userLocUrl" is partly formed by user input from text box -which I've tied to an ng-model and referenced from $scope variables "city" & "country".

And other controllers refere to - userLocUrl as follows:

app.controller('tempCtrl', function($rootScope,$scope,$http) {

$scope.temp = {};   

if($rootScope.flag=="y"){

$http.get($rootScope.userLocUrl)
.success(function (data) {
        alert("temp");
        angular.element('#temperature').scope().temp = data;
        angular.element('#temperature').scope().$apply();
        });
//alert("Almost at end");
}

});

So I want them to execute only after the first controller executes and sets the 2 $rootScope variables to appropriate values.

How to do this in AngularJS?

1

1 Answers

0
votes

You can use angular event system, eg broadcast , on, emit among controllers to control work flow.