AngularJs String Slice JavaScript


AngularJs String Slice: Slice Method is used to extract parts of string. We can use JavaScript slice() method to extract parts of string. Here in this tutorial we are going to explain how you can use JavaScript slice() method to extract parts of a string. You can also use our online editor to edit and run the code online.


AngularJs String Slice JavaScript Example

We can use JavaScript Slice() method to extract a part of string. Let us create an example to understand this in AngularJs-

AngularJs String Slice 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.sliceExample = function(){
  $scope.result = $scope.exampleString.slice(1,4);
 }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="sliceExample()">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 sub part from the string. If you run the above example it will produce output something like this –

AngularJs String Slice JavaScript Example

Advertisements

Add Comment

📖 Read More