Hi I'm using a directive on the body tag to capture global events such as mousedown, mouseup, scroll etc. I was wondering if there is a possible way to allow the usage of an angular directive only once (kind of the singleton concept) or alternatively if a directive can be used only by a certain html tag (in my case the body tag).
Directive:
angular.module('app.helper', [])
.directive('globalEvents', ['$document', function($document) {
return function(scope, element, attrs) {
element.bind('mousedown', function(e) {
// some action
});
$document.bind('scroll', function(e) {
// some action
});
}
}]);
View:
<body global-events>
...<div global-events></div><- is it possible to disallow this or any other usage of the directive
</body>