Created
November 6, 2014 13:09
-
-
Save juristr/8153001bed4f3462c8c7 to your computer and use it in GitHub Desktop.
Restrict directive
This file contains hidden or 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
<!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