You can resolve
data into your state when you transition into it, usually it's useful when the state needs to use that data, or to resolve into a state when some provided input needs to be authenticated.
When you define your states, you will need to provide a map of values to be resolved into the .resolve
property, each resolved value should have a function that returns a promise
.state('main', {
url: "/main",
templateUrl: "path/to/main.html",
controller: 'mainCtrl',
resolve: {
serverData: function ($http) {
return $http.get('some/url');
}
}
});
Now, inside the mainCtrl
you can access the data (that is if the $http
call resolved successfully).
.controller("mainCtrl", function($scope, serverData) {
$scope.resolvedData = serverData.then(resp=> resp.data);
....
})