So, consider the following snippet from my angularUI routing setup. I am viewing the route / category / management / 4 / details (for example). I expect the โcategoryโ to be resolved before the corresponding controller is loaded, and indeed, to the extent that I can put a breakpoint inside the permission function, which returns the category from the category service and sees that the category has been returned. Now, putting another breakpoint inside the controller itself, I see that the "category" is always undefined. It is not entered by the user interface router.
Can anyone see the problem? It may be somewhere else than in the code I provided, but since I have no errors when running the code, it is impossible to determine where the source of the problem may be. Typical failures of silence!
.state('category.manage', { url: '/manage', templateUrl: '/main/category/tree', controller: 'CategoryCtrl' }) .state('category.manage.view', { abstract: true, url: '/{categoryId:[0-9]*}', resolve: { category: ['CategoryService', '$stateParams', function (CategoryService, $stateParams) { return CategoryService.getCategory($stateParams.categoryId).then(returnData); //this line runs before the controller is instantiated }] }, views: { 'category-content': { templateUrl: '/main/category/ribbon', controller: ['$scope', 'category', function ($scope, category) { $scope.category = category; //category is always undefined, ie, UI router is not injecting it }] } }, }) .state('category.manage.view.details', { url: '/details', data: { mode: 'view' }, templateUrl: '/main/category/details', controller: 'CategoryDetailsCtrl as details' })
source share