我有以下設置:不同的數據使用相同的控制器兩次
<h2>Current Items</h2>
<table ng-controller="ItemsController">
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
</tr>
</table>
<h2>Past Items</h2>
<table ng-controller="ItemsController">
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
</tr>
</table>
<script>
var app = angular.module('app');
app.factory('Items', ['$resource', function ($resource) {
return $resource('/api/items/:id/', {id: '@id'});
}]);
app.controller("ItemsController", function($scope, Items) {
$scope.items = Items.query({type: 'current'});
});
</script>
我不明白如何再利用HTML表格和控制器,而是通過對類型不同的值,所以該項目服務返回兩個表的不同結果。
我知道我可以創建兩個控制器並從一個BaseItemsController繼承,但它看起來不正確。任何更好的想法?
謝謝!