AngularJs Substring


AngularJs Substring: JavaScript substring Method is used to extract characters of string between two specified positions ie start and end. Here in this tutorial we are going to explain how you can use JavaScript substring() method to extract character from string. You can also use our online editor to edit and run the code online.


AngularJs Substring JavaScript Example

Let us create an example to understand how to use JavaScript substring function to extract the characters in AngularJs-

AngularJs Substring Method 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.substringExample = function(){
  $scope.result = $scope.exampleString.substring(1,4);
 }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="substringExample()">Click Me</button>
<p>Result = {{result}}</p>
</div> 
</div>
</body>  
</html>  

Try it »

In the above example we have created an example which will extract characters from the string.
If you run the above example it will produce output something like this –

AngularJs Substring JavaScript Example


Advertisements

Add Comment

📖 Read More