AngularJS filter to trim white space angularjsjavascriptjssnippet Filter in AngularJS to trim white space. 12345678app.filter('trim', function () { return function(value) { if(!angular.isString(value)) { return value; } return value.replace(/^\s+|\s+$/g, ''); // you could use .trim, but it's not going to work in IE<9 };}); and then 1<div>{{ string | trim }}</div>