I want to limit as much possible the "flickering" in my AngularJS application. I use resolve: from the router (works with ngRouter and ui-router) to load the data so that everything needed to display my page is available before changing the route.
Common example:
.state('recipes.category', {
url: '/:cat',
templateUrl: '/partials/recipes.category.html',
controller: 'RecipesCategoryCtrl as recipeList',
resolve: {
category: ['$http','$stateParams', function ($http, $stateParams) {
return $http.get('/recipes/' + $stateParams.cat).then(function(data) { return data.data; });
}]
}
});
Now my RecipesCategoryCtrl controller can load category and the promise will be directly resolved.
Is there a way to embed the loading code directly inside my controller? Or somewhere else more "clean"? I don't like having too much logic inside the route definition…
Something like:
.state('recipes.category', {
url: '/:cat',
templateUrl: '/partials/recipes.category.html',
controller: 'RecipesCategoryCtrl as recipeList',
resolve: 'recipeList.resolve()' // something related to RecipesCategoryCtrl and "idiomatic" AngularJS
});