Skip to content

Instantly share code, notes, and snippets.

@pratik14
Created October 17, 2015 11:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pratik14/35ffcb3ba1e020170b43 to your computer and use it in GitHub Desktop.
Save pratik14/35ffcb3ba1e020170b43 to your computer and use it in GitHub Desktop.
(function(){
angular.module('AppName')
.directive('restrict', [function(){
return({
restrict: 'A',
prioriry: 100000,
scope: false,
link: function(scope, element, attr) {
var accessDenied = true;
var role_code = scope.user.role_code;
var attributes = attr.access.split(" ");
for(var i in attributes){
var attrs = attributes[i].split(',');
if(attrs.indexOf(role_code) != -1){
accessDenied = false;
}
}
if(accessDenied){
element.children().remove();
element.remove();
}
}
})
}]);
})();
//Html Code.
//Access variable takes name of roles
<li restrict access=admin class="sub-menu">
<a ui-sref="example.index">
<span> Example </span>
</a>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment