【发布时间】:2015-06-26 09:02:33
【问题描述】:
我是 Angular 的新手,我仍然按照教程和其他东西来解决问题。我需要以下帮助。 我有一个看起来像这样的控制器。
app.controller('ScheduleBooking', ['$http', function($http){
var schedule = this;
schedule.databooking = [];
$http.post('../getbookings.json').
success(function(data, status, headers, config) {
schedule.databooking = data;
}).
error(function(data, status, headers, config) {
console.log('failed');
});
}]);
一个控制器,它调用 $http 服务来获取预订列表,我在 HTML 中使用 ng-repeat 填充响应。
我有另一个这样的控制器。
app.controller('MakeBooking', ['$http', function($http){
var makeBooking = this;
//somecode here
$http.post('../MakeBooking.json?name=burhan').
success(function(data, status, headers, config) {
// I WANT TO REFRESH THE LIST OF BOOKINGS.
//I am looking a way to call scheduleBooking controller so that
//it can make http call and refresh the list of booking in html.
}).
error(function(data, status, headers, config) {
console.log('failed');
});
}]);
所以场景是:当页面加载时,客户应该看到他所做的所有预订。当他进行预订时,会调用 http 服务进行预订,并且在此服务成功回调中,我想做一些事情,以便它可以通过调用 Schedule booking 控制器中定义的 http 服务来刷新预订列表。 也许我可以用 BROADCAST 和 ON 方法做到这一点。但我不确定。在我已经用 JQuery 编写的应用程序中发生了很多类似的事情。 做这个的最好方式是什么?可能是我完全错了,还有其他更好的方法可以做到这一点。 你们有什么建议?
【问题讨论】:
标签: angularjs http callback controller angularjs-service