有没有办法搜索while循环填充数据与angularjs

时间:2017-05-03 17:50:31

标签: javascript php jquery angularjs html5

我有一个位置,我以前的代码是2000到3000行,所以我不希望angular $httppopulate我页面上的所有数据。我想在search php数据上使用populated功能。

问题:如何在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>

请提前帮助我!!!!!!!!!!!!!!!!!!!!!!!

1 个答案:

答案 0 :(得分: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");
           });  

          };
        });