MCPcopy
hub / github.com/angular-ui/ui-grid / createEventDirective

Function createEventDirective

lib/test/angular/1.8.0/angular.js:29007–29037  ·  view source on GitHub ↗
($parse, $rootScope, $exceptionHandler, directiveName, eventName, forceAsync)

Source from the content-addressed store, hash-verified

29005);
29006
29007function createEventDirective($parse, $rootScope, $exceptionHandler, directiveName, eventName, forceAsync) {
29008 return {
29009 restrict: 'A',
29010 compile: function($element, attr) {
29011 // NOTE:
29012 // We expose the powerful `$event` object on the scope that provides access to the Window,
29013 // etc. This is OK, because expressions are not sandboxed any more (and the expression
29014 // sandbox was never meant to be a security feature anyway).
29015 var fn = $parse(attr[directiveName]);
29016 return function ngEventHandler(scope, element) {
29017 element.on(eventName, function(event) {
29018 var callback = function() {
29019 fn(scope, {$event: event});
29020 };
29021
29022 if (!$rootScope.$$phase) {
29023 scope.$apply(callback);
29024 } else if (forceAsync) {
29025 scope.$evalAsync(callback);
29026 } else {
29027 try {
29028 callback();
29029 } catch (error) {
29030 $exceptionHandler(error);
29031 }
29032 }
29033 });
29034 };
29035 }
29036 };
29037}
29038
29039/**
29040 * @ngdoc directive

Callers 2

addEventDirectiveFunction · 0.85
angular.jsFile · 0.85

Calls 2

$parseFunction · 0.70
callbackFunction · 0.70

Tested by

no test coverage detected