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