diff --git a/src/js/soloPositivos-directive.js b/src/js/soloPositivos-directive.js new file mode 100644 index 0000000..09867d1 --- /dev/null +++ b/src/js/soloPositivos-directive.js @@ -0,0 +1,29 @@ +angular.module('focaDirectivas') + .directive('soloPositivo', function(){ + return { + require: 'ngModel', + scope: true, + link: function(scope, element, attr, ngModel) { + ngModel.$parsers.push(function (value) { + return '' + value; + }); + + if(!ngModel) return; + + function test(texto) { + console.log('Texto: ', element); + console.log('Valor 2: ',attr); + if (texto) { + var cambioInput = texto.replace('-',''); + + if (cambioInput !== texto) { + ngModel.$setViewValue(cambioInput); + ngModel.$render(); + } + return cambioInput; + } + } + ngModel.$parsers.push(test); + } + }; + }); \ No newline at end of file