I'm creating a directive that should dynamically include a function in the ng-keyup
angular event, I tried to do this:
Directive
angular.module('app').directive('validar',validar);
validar.$inject = [];
function validar(){
var diretica = {
restrict: 'E',
require: '?ngModel',
scope: {
validador: '&'
},
templateUtl: '....html template segue abaixo',[
link: link
};
return diretiva;
function link(scope, element, attrs, ngModel) {
if (scope.validator !== undefined) {
element[0].setAttribute("ng-keyup", "validador()");
}
}
}
HTML
<input type="text" ng-model="ngModel" />
Problem
I was able to create the attribute in the element, but the angle does not execute the function. When I manually include the attribute in html in this way everything works.
<input type="text" ng-model="ngModel" ng-keyup="validador()" />
According to the colleague's response, the DOM was already rendered when my directive includes the attribute dynamically, so the attribute exists in the element, but the angle does not recognize it.