How to do basic search functionality in angularJs


Search

We can do basic search functionality in angularJs using filter like given below example. I hope this code we can also use in real time application.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script src="../Scripts/angular.js"></script>
    <script>
        var app = angular.module("MyApp", []);
        app.controller("MyController", function ($scope) {
            $scope.EmpName = [
                     { Name:'Ram', City:'Bangalore'},
                    { Name:'Mohan', City:'Bangalore'},
                    {Name:'Jon', City:'Bangalore'},
                    {Name:'Rohan', City:'Nepal'}
                                ];
                                });

    </script>
</head>
<body ng-app="MyApp">
    <div ng-controller="MyController">
        <p>Enter the Name to be Search <input type="text" name="EmpNameSearch" ng-model="EmpNameSearch" /> </p>
        <table style="border:1px solid" border="1">
            <tr ng-repeat="x in EmpName |filter:EmpNameSearch">
                <td style="width:200px;">{{x.Name}}</td>
                <td style="width:200px;">{{x.City}}</td>
            </tr>
        </table>
    </div>
</body>
</html>

Summary:

We learnt how to use basic search functionality using AngularJs Filter functionality.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: