I have a custom directive that creates a field as part of a larger form. Vastly simplified, it looks like this:
.directive('entityField', function () {
return {
restrict: 'E',
scope: {
field: '=',
attributes: '=',
editMode: '='
},
templateUrl: '<input ng-blur="blur()" type="text"/>',
link: function (scope, element, attrs) {
scope.blur = function() {
// call out to event listeners that blur event happened
}
}
};
});
My goal is to have the directive fire an event on blur of its input element so that the surrounding controller can handle the blur event and perform some complex validation.
So, how do I raise an event in a directive such that the surrounding controller can listen for it?
linkfunction with:controller: function($scope) { $scope.blur = function() {} }- not 100% if that'll work.