MCPcopy Index your code
hub / github.com/angular-ui/ui-router / createEventDirective

Function createEventDirective

test/angular/1.7/angular.js:28942–28972  ·  view source on GitHub ↗
($parse, $rootScope, $exceptionHandler, directiveName, eventName, forceAsync)

Source from the content-addressed store, hash-verified

28940);
28941
28942function createEventDirective($parse, $rootScope, $exceptionHandler, directiveName, eventName, forceAsync) {
28943 return {
28944 restrict: 'A',
28945 compile: function($element, attr) {
28946 // NOTE:
28947 // We expose the powerful `$event` object on the scope that provides access to the Window,
28948 // etc. This is OK, because expressions are not sandboxed any more (and the expression
28949 // sandbox was never meant to be a security feature anyway).
28950 var fn = $parse(attr[directiveName]);
28951 return function ngEventHandler(scope, element) {
28952 element.on(eventName, function(event) {
28953 var callback = function() {
28954 fn(scope, {$event: event});
28955 };
28956
28957 if (!$rootScope.$$phase) {
28958 scope.$apply(callback);
28959 } else if (forceAsync) {
28960 scope.$evalAsync(callback);
28961 } else {
28962 try {
28963 callback();
28964 } catch (error) {
28965 $exceptionHandler(error);
28966 }
28967 }
28968 });
28969 };
28970 }
28971 };
28972}
28973
28974/**
28975 * @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