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">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <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();
 }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="trimExample()">Click Me</button>
<p>Result = {{result}}</p>
</div> 
</div>
</body>  
</html>  

Try it »

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

AngularJs Trim String Example


Advertisements

Add Comment

📖 Read More