I have a big number of angularjs routes in my app. I would like to set access to these route based on some user permission levels.
angular.module('myApp').run(['$rootScope', 'someAuthFactory', function($rootScope, someAuthFactory) { $rootScope.$on('$stateChangeStart', function (event, toState) { $rootScope.permissions = someAuthFactory.getPermssionLevels(); $rootScope.specialRights = $rootScope.permissions.indexOf('superRole') > -1; ... and here is one of my routes:
.state("dashboard.overview", { url: "/dashboard", templateUrl: "app/dashboard.html", resolve: { roles: ['rootScope', function (rootScope) { return $rootScope.specialRights;}] }, so this code works, but if i want to add this:
resolve: { roles: ['rootScope', function (rootScope) { return $rootScope.specialRights;}] } to every route, it is gonna be duplicate code, or if I want to lookup some other role, it is gonna be boring. Could we make the resolve part much smaller and much cleaner?