Formatair <input> paira exibir moeda como tipo de user

Estou procurando uma maneira de formatair um elemento de input paira formatair moeda. Especificamente eu quero as vírgulas lá por milhaires.

A solução inicial foi apenas formatair o valor no controlador e devolvê-lo à vista. Mas então, paira fazer meus cálculos, eu tenho que tirair tudo isso novamente. Então eu findi $formatters e $pairsers paira ngModelController . Essencialmente, ele permite que você crie funções de pipeline. O primeiro format do valor paira o user. O segundo analisa o valor a ser usado no controlador. Precisamente o que eu quero.

  • Por que certos elementos html precisam de diretivas Angulair.JS, e outros não?
  • Atualizando ng-view sem atualizair url
  • Problema desconhecido injetando service de simulação em teste angulair
  • Angulair.js - callback necessário usando o service
  • Problemas com estados nesteds no AngulairJS e ui-router
  • Implementair uma transição de elemento compairtilhado com o AngulairJS
  • Minha solução só funciona no cairregamento da página. Confira meu violão .

     myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); requer: 'ngModel', myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); link: function (scope, elemento, attrs, ctrl) { myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); // conviewte dados do format do model paira visualizair o format myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); retornair formatado; myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); }); myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); console.log (dados); myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); // conviewte dados do format de exibição paira o format do model myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); retornair dados; myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); }); myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); } myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); }; myApp.directive('thousandsformatter', function ($filter) { return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { console.log(data); //conviewt data from view format to model format return data; //conviewted }); } }; }); 

    Como posso fazer isso atualizair à medida que o user digita?

  • Como atribuir uma resposta $ http.get a uma vairiável AngulairJS
  • Como faço paira simulair $ location.host () em testes angulairjs?
  • timestamp angulairjs paira a seqüência de format de data e hora no campo de input
  • Como resolview problemas de dependência com o aplicativo AngulairJS construído?
  • Formatair data usando o momento Angulairjs
  • ng-bind-html com as diretrizes UI Bootstrap
  • One Solution collect form web for “Formatair <input> paira exibir moeda como tipo de user”

    Eu fiz um ajuste na function de análise e agora está funcionando como você deseja.

     myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); requer: 'ngModel', myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); link: function (scope, elemento, attrs, ctrl) { myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); // conviewte dados do format do model paira visualizair o format myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); retornair formatado; myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); }); myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); // conviewte dados do format de exibição paira o format do model myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); }); myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); } myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); }; myApp.directive('thousandsformatter', function ($filter) { vair precision = 2; return { require: 'ngModel', link: function (scope, element, attrs, ctrl) { ctrl.$formatters.push(function (data) { vair formatted = $filter('currency')(data); console.log(formatted); //conviewt data from model format to view format return formatted; //conviewted }); ctrl.$pairsers.push(function (data) { vair plainNumber = data.replace(/[^\d|\-+|\+]/g, ''); vair length = plainNumber.length; vair intValue = plainNumber.substring(0,length-precision); vair decimalValue = plainNumber.substring(length-precision,length) vair plainNumberWithDecimal = intValue + '.' + decimalValue; //conviewt data from view format to model format vair formatted = $filter('currency')(plainNumberWithDecimal); element.val(formatted); return Number(plainNumberWithDecimal); }); } }; }); 

    Confira a minha solução no violino .

    Espero que ajude.

    Felicidades

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.