AngularJS Tutorial - Filter a List of DOM Nodes








The following code shows how to filter a List of DOM Nodes.

Example


<!doctype html>
<html  ng-app="MyApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
    <script>
var app   =  angular.module("MyApp", []);
<!--from   ww  w. j av  a2 s .  com-->
 app.filter("exclude",  function() {
      return  function(input,  exclude) {
           var result  =  [];
           for (var i=0; i<input.length;  i++)  {
                if (input[i]  !==  exclude)  {
                     result.push(input[i]);
                }
           }

           return  result;
      };
 });  
    </script>
  </head>
  <body>
     <ul ng-init="names =  ['A',  'B',  'C']"> 
          <li  ng-repeat="name in  names   | exclude:'B' ">
               <span>{{name}}</span>
          </li>
     </ul>

  </body>
</html>

The code above is rendered as follows: