AngularJs Check String StartsWith


AngularJs Check String StartsWith: We can use JavaScript startsWith() method to check whether a string starts with certain characters. Here in this tutorial we are going to explain how you can use JavaScript startsWith() function to check whether the string starts with certain characters in AngularJs.


AngularJs Check String StartsWith Example

JavaScript startsWith() method checks whether a string starts with certain characters. This method returns true if the character match is found at the starting of the string else it will return false. Let us create an example to understand how we can use JavaScript startswith method in AngularJs.

AngularJs Check String StartsWith 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.startswithExample = function(){
  $scope.result = $scope.exampleString.startsWith("Hello");
 }
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="startswithExample()">Click Me</button>
<p>Result = {{result}}</p>
</div> 
</div>
</body>  
</html>  

Try it »

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

AngularJs Check String StartsWith Example

Advertisements

Add Comment

📖 Read More