AngularJs String Search

AngularJs String Search: Sometimes we need to search a value in specified String In AngularJs, we can use JavaScript search() method to search the value in Specified String. Here in this tutorial we are going to explain how you can use JavaScript Search function to search the specified value in AngularJs String.

AngularJs String Search Example

JavaScript search() method searches a value in string and returns the position of the match. The search value can be string or regular expression. If the match is not found it will return -1. Let us create an example to understand how we can use JavaScript Search method in AngularJs.

AngularJs String Search 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.searchExample = function(){
  $scope.result = $"World");
<div ng-app="myApp">  
<div ng-controller="myController"> 
<button type="button" ng-click="searchExample()">Click Me</button>
<p>Result = {{result}}</p>

Try it »

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

AngularJs String Search Example


Add Comment

📖 Read More