I want to create an attribute directive like ngDisabled to enable or disable elements if some specific role is present on my service.
angular.module(...)
.service('RolesSerivce', function() {
this.hasRole = function(roleName) {
return this.roles.indexOf(roleName)>1;
};
this.setRoles = function(rolesArr) {
this.roles = rolesArr;
};
this.setRoles(['ROLE_CAN_CLICK'])
}).direcive('hasRole', function() {
??????????????????
// use RolesSerivce.hasRole inside implemetation
??????????????????
});
On my HTML I want to use the directive like this:
<button has-role="ROLE_CAN_CLICK" ng-disabled="extraValidation > 0">Click me</button>
On the example above, the has-role
directive must override the ng-disable
, it must be mandatory. But the ng-disable
must run when the has-role
is true
.
My question, can someone help me with the directive implementation? How can I do this?