Guest User

Untitled

a guest
Apr 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. ctrl.$setViewValue(_formatContaBanco(scope.model));
  2.  
  3. ngModel.$formatters.push(function(value) {
  4. return value.toUpperCase();
  5. });
  6.  
  7. ngModel.$parsers.push(function(value) {
  8. return value.toLowerCase();
  9.  
  10. angular.module('app').directive('contaCorrenteMask', function () {
  11. return {
  12. restrict: 'A',
  13. require: "ngModel",
  14. link: function (scope, element, attrs, ctrl) {
  15.  
  16. var _formatContaBanco = function (data) {
  17.  
  18. if (!data)
  19. return data;
  20.  
  21. if (data.length == 1)
  22. return data;
  23.  
  24. data = data.replace(/[^0-9]+/g, "");
  25.  
  26. var digito = data.slice(-1);
  27. var conta = data.slice(0, -1);
  28.  
  29. return conta + '-' + digito;
  30. };
  31.  
  32. // Send out changes from inside:
  33. ctrl.$formatters.push(function (modelValue) {
  34. return _formatContaBanco(modelValue);
  35. });
  36. }
  37. };
  38. })
Add Comment
Please, Sign In to add comment