Created
October 17, 2015 11:49
-
-
Save pratik14/35ffcb3ba1e020170b43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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