2015-09-21 47 views
0

我有一個使用兩個表的角度應用程序。頂層表應該搜索兩個表的數據,但是,他們使用兩個不同的控制器。我怎樣才能使用簡單的服務或工廠獲得頂級桌面?AngularJs:用ng-repeat與兩個不同的控制器進行搜索

div ng-controller="topCtrl"> 
    <tr ng-repeat="data in myData | filter:search"> 
      <td><input type="checkbox"/></td> 
      <td>{{ data.number }}</td> 
      <td>{{ data.street }}</td> 
     </tr> 
</div> 

div ng-controller="botCtrl"> 
    <tr ng-repeat="data in myData2 | filter:search2"> 
      <td><input type="checkbox"/></td> 
      <td>{{ data.number }}</td> 
      <td>{{ data.street }}</td> 
     </tr> 
</div> 

回答

0

您可以直接包括服務到您的SEARCHQUERY

Demo

angular.module('myApp').controller('topCtrl', function topCtrl($scope, searchService) { 
    $scope.myData = ["A", "B"]; 
    $scope.searchService = searchService; 
}); 

angular.module('myApp').controller('botCtrl', function botCtrl($scope, searchService) { 
    $scope.myData2 = ["A", "B"]; 
    $scope.searchService = searchService; 
}); 

<div ng-app="myApp"> 
    <div ng-controller="topCtrl"> 
     <input type="text" ng-model="searchService.search"/> 
     <table> 
      <tr ng-repeat="data in myData | filter:searchService.search"> 
       <td>{{ data }}</td> 
      </tr> 
     </table> 
    </div> 
    <hr/> 
    <div ng-controller="botCtrl"> 
     <table> 
      <tr ng-repeat="data in myData2 | filter:searchService.search"> 
       <td>{{ data }}</td> 
      </tr> 
     </table> 
    </div> 
</div> 
+0

謝謝,這個偉大的工程! –

相關問題