Just add it as a dependency on your directive, and $ q will be used as a link function. This is due to JavaScript closures .
The following is an example based on your code.
angular.module('directives') .directive('myDirective', ['$q', function($q) { return { scope: { onEvent: '&' } // ... link: function($scope, $element) { $scope.handleEvent() { $q.when($scope.onEvent()) { ... } } } } }])
source share