2017-05-03 65 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搜索
相關問題