AngularJs String Search – String Search AngularJs
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.
Html of AngularJs String Search Example
<div ng-app="myAppSearch"> <div ng-controller="myControllerSearch"> <button type="button" ng-click="searchExample()">Click Hear for Angular String Search</button> <p>Result = {{result}}</p> </div> </div>
script of Angular String Search Example
var myAppSearch = angular.module("myAppSearch", []); myAppSearch.controller("myControllerSearch", function($scope) { $scope.exampleString = "This is Hello World!"; $scope.result = ''; $scope.searchExample = function(){ $scope.result = $scope.exampleString.search("is"); } });
AngularJs String Search Example:
<!DOCTYPE html> <html lang="en"> <head> <title>Angularjs String Search - onlinecode</title> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myAppSearch = angular.module("myAppSearch", []); myAppSearch.controller("myControllerSearch", function($scope) { $scope.exampleString = "This is Hello World!"; $scope.result = ''; $scope.searchExample = function(){ $scope.result = $scope.exampleString.search("is"); } }); </script> </head> <body> <div ng-app="myAppSearch"> <div ng-controller="myController"> <button type="button" ng-click="searchExample()">Click Hear for AngularJs String Search</button> <p>Result = {{result}}</p> </div> </div> </body> </html>
You also like AngularJs Pass Data to $http.get request AND AngularJs Call Function on Page Load with example