I have defined my user roles and permissions in my application as per the documentation.
https://github.com/Narzerus/angular-permission/wiki
With this I am able to use the ui directives or ui-router handling.
Q: How to test that a user has a role or permission within a controller or service?
(function() {
'use strict';
angular
.module('app')
.component('userDetail', component());
/** @ngInject */
function component() {
return {
restrict: 'E',
bindings: {
user: '<'
},
templateUrl: 'app/components/users/user-detail/user-detail.html',
transclude: true,
controller: Controller
}
}
/** @ngInject */
function Controller($log) {
var ctrl = this;
ctrl.$onInit = function() {
$log.log('How to test for user permission?')
// Something like...
// if(PermPermission.hasPermission('createUser')) {
// do something
// }
};
}
})();