techie_questie
techie_questie

Reputation: 1522

Angular js way to add commas for amount based on no. of digits, once user tabs out and to auto add .00 for non decimal amount in input box

I am new to angular. The requirement is-

I have an input field for amount in different currency.My requirement is that ,Once user tabs out,I want the comma to get added automatically, based on number of digits in the amount.Also,if amount entered does not include a decimal value,then .00 should get auto added to the amount.

Upvotes: 1

Views: 1239

Answers (1)

Ulrich Fischer
Ulrich Fischer

Reputation: 173

first create an input with a directive (add-commas in this case)

<input type="text" add-commas />

Create a directive that registers an event handler for the inputs blur event like so

angular.module('app', [])
.directive('addCommas', function(){
  return {
    link: function(scope, el, attrs){

      el.bind('blur', function(){

        // Add the commas and stuff 
      });
    }
  }
});

I created a plunker that should meet your requirements.

Hope this helps

Upvotes: 1

Related Questions