From a598f74c0c31dd6e9c9adad189d48d2c306b5e99 Mon Sep 17 00:00:00 2001 From: Luigi Date: Mon, 18 Mar 2019 11:36:28 -0300 Subject: [PATCH] Directiva para numeros positivos --- src/js/soloPositivos-directive.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/js/soloPositivos-directive.js 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 -- 1.9.1