Commit 773436bd02d351297af034af3f8f51f208eb642c
1 parent
c9baa0e8ef
Exists in
master
and in
1 other branch
nuevas directivas
Showing
2 changed files
with
47 additions
and
0 deletions
Show diff stats
src/js/stringToNumber-directive.js
... | ... | @@ -0,0 +1,14 @@ |
1 | +angular.module('focaDirectivas') | |
2 | + .directive('stringToNumber', function () { | |
3 | + return { | |
4 | + require: 'ngModel', | |
5 | + link: function (scope, element, attrs, ngModel) { | |
6 | + ngModel.$parsers.push(function (value) { | |
7 | + return '' + value; | |
8 | + }); | |
9 | + ngModel.$formatters.push(function (value) { | |
10 | + return parseFloat(value); | |
11 | + }); | |
12 | + } | |
13 | + }; | |
14 | + }); | |
0 | 15 | \ No newline at end of file |
src/js/uppercaseOnly-directive.js
... | ... | @@ -0,0 +1,33 @@ |
1 | +angular.module('focaDirectivas') | |
2 | + .directive('uppercaseOnly', [ | |
3 | + function() { | |
4 | + return { | |
5 | + restrict: 'A', | |
6 | + require: 'ngModel', | |
7 | + link: function(scope, element, attrs, ctrl) { | |
8 | + | |
9 | + function parser(value) { | |
10 | + if (ctrl.$isEmpty(value)) { | |
11 | + return value; | |
12 | + } | |
13 | + var formatedValue = value.toUpperCase(); | |
14 | + if (ctrl.$viewValue !== formatedValue) { | |
15 | + ctrl.$setViewValue(formatedValue); | |
16 | + ctrl.$render(); | |
17 | + } | |
18 | + return formatedValue; | |
19 | + } | |
20 | + | |
21 | + function formatter(value) { | |
22 | + if (ctrl.$isEmpty(value)) { | |
23 | + return value; | |
24 | + } | |
25 | + return value.toUpperCase(); | |
26 | + } | |
27 | + | |
28 | + ctrl.$formatters.push(formatter); | |
29 | + ctrl.$parsers.push(parser); | |
30 | + } | |
31 | + }; | |
32 | + } | |
33 | + ]); | |
0 | 34 | \ No newline at end of file |