I was wondering, if it is possible, to extend Angular's input directive? I want to attach some listeners to all input fields on a page. I think you can decorate existing modules with $provide.decorate
, but I have no idea how to do this with a directive (and more precisely the input directive).
So, can anyone push me in the right direction? Some examples?
EDIT
Here is my directive that I have so far:
angular.module('onFocusBlur'). directive('onFocusBlur', ["$rootScope", function($rootScope) { return { restrict: "A", link: function(scope, elem, attrs) { elem.bind('focus',function() { scope.$apply(function() { $rootScope[attrs.onFocusBlur] = true; }); }); elem.bind('blur',function() { scope.$apply(function() { $rootScope[attrs.onFocusBlur] = false; }); }); } }; }]);
In my view, I can add this to an input field like this:
<input type="email" ng-model="email" on-focus-blur="repositionNavBar">
The downside is, that for every input field, I have to attach this listener manually in my code. Therefore, it would be useful, to alter the existing input directive, to include this listeners.