Skip to content

Instantly share code, notes, and snippets.

@juristr
Created November 6, 2014 13:09
Show Gist options
  • Save juristr/8153001bed4f3462c8c7 to your computer and use it in GitHub Desktop.
Save juristr/8153001bed4f3462c8c7 to your computer and use it in GitHub Desktop.
Restrict directive
<!doctype html>
<html ng-app="myApp">
<head>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
</head>
<body>
<h1>Tests</h1>
<p>You shouldn't see the text below:</p>
<div restrict grants="admin">Hi there</div>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script>
angular.module('myApp', [])
.directive('restrict', function(){
return {
restrict: 'A',
compile: function(tElement, attributes){
var accessGranted = false; // here is the right call
if(accessGranted === false){
tElement.children().remove();
tElement.remove();
}
}
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment