AngularJs Trim String

AngularJs Trim String: You can use JavaScript trim() method to remove spaces from both end. Here in this tutorial we are going to explain how you can use this function to remove spaces in AngularJs. You can also use our online editor to edit and run the code online.

AngularJs Trim String Example

JavaScript trim() function removes spaces from both end of the string, You can also use the same in AngularJs to remove the blank spaces from String. Here is an example to remove the spaces from the string in AngularJs-

AngularJs Trim String Example:

<!DOCTYPE html>
<html lang="en">
 <script src="//"></script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.exampleString = " Hello World! ";
 $scope.result = '';
 $scope.trimExample = function(){
  $scope.result = $scope.exampleString.trim();
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="trimExample()">Click Me</button>
<p>Result = {{result}}</p>

Try it »

If you run the above example it will produce the output something like this –

AngularJs Trim String Example


Add Comment

📖 Read More