AngularJs String SubStr

AngularJs String SubStr: JavaScript SubStr Method is used to extract parts of string between two specified positions ie. start and end and it returns the string between the specified location. Here in this tutorial we are going to explain how you can use JavaScript substr() method to extract parts of a string. You can also use our online editor to edit and run the code online.

AngularJs String SubStr JavaScript Example

Let us create an example to understand how to use JavaScript substr function in AngularJs-

AngularJs String SubStr Method 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.substrExample = function(){
  $scope.result = $scope.exampleString.substr(1,4);
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="substrExample()">Click Me</button>
<p>Result = {{result}}</p>

Try it »

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

AngularJs String SubStr Example


Add Comment

📖 Read More