If you want to control access to different content, you can create a system similar to this one. Keep in mind the importance of securing your backend as well.
In the configuration for ui.router where you define your states, you have the option to include user-defined data. For instance:
angular.module("app", ['ui.router']).config(['$stateProvider', function($stateProvider){
$stateProvider.state('restrictedState', {
url: '/restricted-state',
templateUrl: '/app/views/restricted.html',
controller: 'RestrictedStateController',
data: {
accessLevel: "restricted-access",
title: 'Restricted State'
}
});
}]);
By adding these details, you can then verify in your authentication service if the necessary access level is granted:
angular.module('app').factory('AuthService', ['$rootScope', function($rootScope){
$rootScope.$on('$stateChangeStart', function (event, nextState) {
if (nextState.data && nextState.data.accessLevel && !service.isAuthorized(nextState.data.accessLevel)) {
event.preventDefault();
alert("Access Denied");
}
});
var service = {
isAuthorized: function(accessLevel) {
//insert your authorization logic here
}
};
return service;
}]);