2017-05-03 64 views
0

我有一个situtation在我的前面的代码是2000到3000行,所以我不想angular$httppopulate我的网页上的所有数据。而我想search功能phppopulated数据。有没有什么办法来搜索上,而与angularjs循环填充数据

问题:如何包括angular搜索功能php populated data

我的搜索按钮:

<input type="search" ng-model="searchText" ng-change="search()"/> 

我的控制器:

myApp.controller('clickListenerCtrl',function($scope,$http){ 

    $scope.search = function(){ 

     console.log($scope.searchText); // im able get typed text 
    } 
}); 

我while循环:

<table ng-controller="clickListenerCtrl"> 
<thead> 
    <tr> 
    <th>Id</th> 
    <th>Name</th> 
    </tr> 
</thead> 
<tbody> 
    <?php while($row = ......){ ?> 
<tr> 
    <td><?php echo $row['id'] ?></td> 
    <td><?php echo $row['name'] ?></td> 
</tr> 
<?php } ?> 
</table> 

在核心angularjs我们可以做这样的(解决方案):

<table ng-controller="clickListenerCtrl"> 
<thead> 
    <tr> 
    <th>Id</th> 
    <th>Name</th> 
    </tr> 
</thead> 
<tbody> 
<tr ng-repeat="x in data | filter:searchText"> 
    <td>{{x.id}}</td> 
    <td>{{x.name}}</td> 
</tr> 
</table> 

请帮我在此先感谢!!!!!!!!!!!!!!!!!!!!!! !

+0

? –

+0

角度搜索 – EaB

+0

为“人口稠密”的前端 – EaB

回答

0

你的控制器也能像这个 -

  myApp.controller('clickListenerCtrl',function($scope,$http){ 

      $scope.search = function(){ 
      console.log($scope.searchText); // im able get typed text      

      //use ajax to call php to fetch serach results and then 
      // display the same in view 
      // then you will not need filter in ng-repeat 

      $http({ 
       url: "search.php", 
       method: 'POST', 
       headers: {'Content-Type': 'application/x-www-form-urlencoded'}, 
       data: 'searchText='+$scope.searchText 
      }).success(function(data, status, headers, config) { 

       console.log(data); 
       $scope.data = data; 


      }).error(function(data, status, headers, config) { 
       $scope.status = status; 
       console.log("error"); 
      }); 

      }; 
     }); 
您要使用的角度或PHP搜索
相关问题