AngularJS Comma Separator

May 16, 2017Angular
Summarize with AI: Google AI Claude ChatGPT Perplexity Grok

AI links open with a title + excerpt (these tools can't fetch the page themselves) — use "Copy full article" to paste the complete text for a fuller summary.

Share:

In this blog, I will demonstrate input textbox, set comma separator, using AngularJS and most useful for quantity and countable input text.

HTML code I have designed simple input type Text in HTML,.using AngularJS

AngularJS Comma Separator

AngularJS code

Create Angular module & name it as csharpcor.

var app = angular.module('csharpcor', []);

Module & controller name must assign to the HTML element

app.controller('NgCtrl', function($scope) {    $scope.TextValues=123456789; });

Module & controller name must assign to the HTML element

Create Angular Directives given below

app.directive('commaseparator', function($filter) {     'use strict';     return {         require: 'ngModel',         link: function(scope, elem, attrs, ctrl) {             if (!ctrl) {                 return;             }             ctrl.$formatters.unshift(function() {                 return $filter('number')(ctrl.$modelValue);             });             ctrl.$parsers.unshift(function(viewValue) {                 var plainNumber = viewValue.replace(/[\,\.\-\+]/g, ''),                     b = $filter('number')(plainNumber);                 elem.val(b);                 return plainNumber;             });         }     }; });

Assgin Directive to the input text.

Output AngularJS For source code, refer to the link.

#AngularJS

Comments

Be the first to comment.

Leave a comment

Never shown publicly.

Comments are reviewed before appearing publicly.