Skip to content

Instantly share code, notes, and snippets.

@builtbylane
Created October 30, 2013 18:43
Show Gist options
  • Select an option

  • Save builtbylane/7237798 to your computer and use it in GitHub Desktop.

Select an option

Save builtbylane/7237798 to your computer and use it in GitHub Desktop.
AngularJS – filter: removes white space from text. useful for html values that cannot have spaces
/**
* Description:
* removes white space from text. useful for html values that cannot have spaces
* Usage:
* {{some_text | nospace}}
*/
app.filter('nospace', function () {
return function (value) {
return (!value) ? '' : value.replace(/ /g, '');
};
});
@pr0r0k131

Copy link
Copy Markdown

dbxfbfng ng fnfgnfgn

@ajgraham671

Copy link
Copy Markdown

thanks for this. worked perfectly. 👍

@hcientist

Copy link
Copy Markdown

I think you would add this to your app's dependencies, and then in the html, you would do {{ yourinfo | nospace }}

@santoshoodles

Copy link
Copy Markdown

can i do something like {{"santoshsingh1988@gmail.com" | remove text after "@" or don't show text after "@"}

@JeanMeche

Copy link
Copy Markdown

@santoshoodles :

app.filter('hidemaildomain', function () {
    return function (value) {
        return (!value) ? '' : value.replace(/@.*/g, '');
    };
});

@danielnaranjo

Copy link
Copy Markdown

Thanks

ghost commented Jan 28, 2015

Copy link
Copy Markdown

great! 😄

@Albinzr

Albinzr commented Mar 26, 2015

Copy link
Copy Markdown

i have a set as { abc,frd,der}
i need to remove comma and add space
how can i do that

@raphaklaus

Copy link
Copy Markdown

Nice way to introduce filters in AngularJS. Thank you.

@MimiBambino

Copy link
Copy Markdown

Thanks. This works perfectly!

@meenakshireka

Copy link
Copy Markdown

if i type one text box value means next text box show remove spaces.

@SujathaMaddala

SujathaMaddala commented Jan 19, 2017

Copy link
Copy Markdown

var app=angular.module("myModule", [])
.controller("myController",function($scope)
{$scope.transformString=function (input){
if(!input){
return input;}
var output="";
for(var i = 0; i < input.length;i++)
{
if(i>=0 && input[i]==input[i].toUpperCase())
{
output = output + " ";
}
output = output + input[i];
} $scope.output=output;
}});
this is the JS code for removing spaces in another text box

Your String Result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment