我有一个Controler1,它会在按钮点击时发送一个事件:
$rootScope.$broadcast('Click');
然后我在Controller2中捕获此事件并更新订单列表:
$scope.$on('Click', function() {
console.log("Somebody clicked the button");
$scope.showingOrders = Order.getMyOrders();
});
其中Order.getMyOrders()向服务器发送订单列表的请求。
Controller2控制了这个:
<div class="list-group">
<a href="#/dashboard" id="{{order.id}}"
data-toggle="modal"
data-target="#showOrderModal"
class="list-group-item"
ng-click="setClickedOrder(showingOrders[$index])"
ng-repeat="order in showingOrders | orderBy : '-id'">
<h4 class="list-group-item-heading">
Order №{{order.id}} from {{order.owner.fullName}}
</h4>
p class="list-group-item-text">{{order.description}}</p>
</a>
</div>
我得到了什么:
Order.getMyOrders()的代码:
app.factory('Order', ['$resource',
function($resource) {
return $resource(BASE_PATH + ORDER_PATH, {}, {
get: {url: BASE_PATH + ORDER_PATH + '/:orderId', method: 'GET', params: {orderId: '@orderId'}},
create: {method: 'POST'},
getNearMe: {url: BASE_PATH + ORDER_PATH + '/near', method: 'GET',
params: {latitude: '', longitude: ''}, isArray: true},
getDoneOrders: {url: BASE_PATH + ORDER_PATH + '/done', method: 'GET',
params: {latitude: '', longitude: ''}},
getMyOrders: {method: 'GET', isArray: true}
});
我做错了什么? 我可以用另一种方式做到这一点吗?