If you are talking about the partials that get loaded in ng-view
, you can use the $routeProvider
resolve
property on the route. This property can take a function which returns a value or promise. In case of promise the view only gets loaded once the promise is resolved. Your code would look something like
$routeProvider.when('/', {
templateUrl: 'app.html',
controller:myAppController,
resolve:{
data:function($http){
return $http.get('url'); //this by default returns promise.
}
}
});
In the controller now you can also inject the data
property of resolve as parameter and access the data.
See this video too to understand resolve http://www.thinkster.io/angularjs/6cmY50Dsyf/angularjs-resolve-conventions