Commit a598f74c0c31dd6e9c9adad189d48d2c306b5e99
1 parent
5d7c5abc85
Exists in
master
Directiva para numeros positivos
Showing
1 changed file
with
29 additions
and
0 deletions
Show diff stats
src/js/soloPositivos-directive.js
| File was created | 1 | angular.module('focaDirectivas') | |
| 2 | .directive('soloPositivo', function(){ | ||
| 3 | return { | ||
| 4 | require: 'ngModel', | ||
| 5 | scope: true, | ||
| 6 | link: function(scope, element, attr, ngModel) { | ||
| 7 | ngModel.$parsers.push(function (value) { | ||
| 8 | return '' + value; | ||
| 9 | }); | ||
| 10 | |||
| 11 | if(!ngModel) return; | ||
| 12 | |||
| 13 | function test(texto) { | ||
| 14 | console.log('Texto: ', element); | ||
| 15 | console.log('Valor 2: ',attr); | ||
| 16 | if (texto) { | ||
| 17 | var cambioInput = texto.replace('-',''); | ||
| 18 | |||
| 19 | if (cambioInput !== texto) { | ||
| 20 | ngModel.$setViewValue(cambioInput); | ||
| 21 | ngModel.$render(); | ||
| 22 | } | ||
| 23 | return cambioInput; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | ngModel.$parsers.push(test); | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | }); |