* Forcing resolution before the controller executes *
.state('state2', {
url: '/state2',
templateUrl: 'page2.html',
controller: 'Page2Ctrl',
resolve: {
gistsData: function(Gists) {
var GistsData = Gists.query();
return GistsData.$promise;
}
}
});
myApp.controller('Page2Ctrl', ['$scope', 'gistsData', function($scope, gistsData) {
$scope.gists = gistsData;
}]);
With the support of $promise to force resolution before the controller executes.
http://www.jvandemo.com/how-to-resolve-angularjs-resources-with-ui-router/
Centrally. Hierarchically. Per state. Using promises. Like a pro.
http://www.jvandemo.com/how-to-resolve-application-wide-resources-centrally-in-angularjs-with-ui-router/
Use AngularUI Router and nested resolves to move data-loading logic out of the controller to avoid code duplication and coupling between controllers.
https://medium.com/opinionated-angularjs/advanced-routing-and-resolves-a2fcbf874a1c#.5hivtypb6