Friday 5 January 2018

custom filter in angularjs

<HTML ng-app = "myapp">   
    <TITLE> AngularJS: Custom Filter</TITLE>   
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>   
    <script>   
       var myapp=angular.module("myapp",[]);   
       myapp.controller("myappcont",function($scope){   
       $scope.students=[   
       {Name:"Kailash",Gender:"Male",Class:"1Std",Section:"A"},   
       {Name:"Kalyan",Gender:"Male",Class:"1Std",Section:"A"},   
       {Name:"Kalyani",Gender:"Female",Class:"1Std",Section:"A"},   
       {Name:"Kamal",Gender:"Male",Class:"2Std",Section:"B"},   
       {Name:"Keshav",Gender:"Male",Class:"2Std",Section:"B"},   
       {Name:"KedarGouri",Gender:"Female",Class:"2Std",Section:"B"}];   
       });   
 myapp.filter('concatenet',function(){   
 return function(input)   
 {   
 return 'Name:'+input.Name+'Gender:'+input.Gender+'Class:'+input.Class+'Section:'+input.Section;   
 }});               
    </script>   
    <BODY ng-controller="myappcont">   
       <table border="1">   
         <tr>   
            <th>Name</th>   
            <th>Gender</th>   
            <th>Class</th>   
            <th>Section</th>   
                          <th>Concatenet Values</th>                             
         </tr>   
         <tr ng-repeat="student in students | filter:searchText">   
            <td>{{student.Name}}</td>   
            <td>{{student.Gender}}</td>   
            <td>{{student.Class}}</td>   
            <td>{{student.Section}}</td>   
                          <td>{{student|concatenet}}</td>                             
         </tr>   
       </table>   
    </BODY>   
  </HTML>  

No comments:

Post a Comment