我有以下设置:不同的数据使用相同的控制器两次
<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继承,但它看起来不正确。任何更好的想法?
谢谢!