March 25, 2016

Remove space in text field using angular.js

Removing space in text field using Angular.js is easy. We can do this by ng-change attribute.

I will show you how to do this in two different ways.

Way 1

Put ng-change attribute to the input field to which you want to the remove white-space.

Say if the ng-model is, then ng-change would be =' ').join('')


<input type="text" ng-model="" ng-change=" =' ').join('')" />

Here it splits the white space and joins it. It's simple right.

Way 2

In this, instead of adding values of ng-change directly to the input we will define it through a function.


<input type="text" ng-model="" ng-change="noSpace()" />


$scope.noSpace = function() {
   $ = $' ').join('');


As your using angular don't forget to import angular.js file.


No comments:

Post a Comment

Popular Posts