2

ここに私の index.html ページがあります ------index.html-------

     <!DOCTYPE html>
         <html>
         <head>
             <script data-require="angular.js@1.4.0-beta.6" data-semver="1.4.0-beta.6"
     src="https://code.angularjs.org/1.4.0-beta.6/angular.js"></script>   
             <script src="script.js"></script>
         </head>
         <body>

     <div ng-app="myApp" ng-controller="PeopleCtrl"> <input type="text"
     name="search1" >

     <input type="submit" ng-model="search1"   value="search"
     ng-click="checkAll"> <table border="1"  ng-init="ageToShow=(people|
     underTwenty: 20).length >= 1">


     <tr name="search1" > <th>Id</th> <th>Name</th> <th ng-show="ageToShow"
    ng-if="!ageToShow">Age</th> </tr> <tr ng-repeat="person in
     people|filter: search" ng-show="person.age>20" >
     <td><span>{{person.id}}</span> </td> <td><span>{{person.name}}</span>
     </td> <td ng-show="!ageToShow"><span>{{person.age}}</span> </td> </tr>
     </table>

     </div> </body> </html>

必要なのは、送信ボタンを使用してレコードを検索することです....そして、ここに私のscript.jsファイルがあります...

--------script.js--------
     // Code goes here



     var myApp = angular.module('myApp', []);

     myApp.controller('PeopleCtrl', function($scope,$filter) {

       $scope.people = ([{
         id: 1,
         name: "Peter",
         age: 22   }, {
         id: 2,
         name: "David",
        age: 12   }, {
         id: 3,
         name: "Anil",
         age: 32   }, {
         id: 4,
         name: "Chean",
         age: 22   }, {
         id: 5,
         name: "Niladri",
         age: 18   }
         ]);





        $scope.people3 = $scope.people;

         $scope.$watch('search1', function(val)
         { 
            $scope.people = $filter('filter')($scope.people3, val);
         });



          }); myApp.filter('underTwenty', function() {

       return function(values, limit) {
         var returnValue = [];
        angular.forEach(values, function(val, ind) {
           if (val.age < limit)

            returnValue.push(val);
             });   return returnValue;   }; });

plunkr.co/edit/?p=preview での私のコーディングは次のとおりです

4

1 に答える 1