【发布时间】:2017-04-09 20:51:26
【问题描述】:
我需要在 2 个请求完成后调用该函数。所以我尝试为此使用 $q.all 。我在 Angular 上有服务,它调用 submitForm,在提交之前我需要再做 2 个请求,在他们响应之后 - 发出提交表单的请求。它看起来像这样:
submitForm : function(form, params) {
var self = this;
var callback = function () {
// this is submit post req
};
angular.forEach(form, function(item) {
// I search tables (type of field) and then send req for saving tables on backend
self.uploadTables(item)
})
this.uploadFiles(params).then(callback)
}
uploadFiles : function(params) {
// this func upload files before submit
}
uploadTables : function(params) {
// for uploading tables I have another service on backend, so I need another request, before submit
}
在$q.all 我想我需要像$q.all(this.uploadFiles, this.uploadTables) 这样称呼它?但是我不能这样做,因为我在 forEach 中调用了uploadTables。完成uploadFiles和uploadTables后如何调用回调函数?
【问题讨论】:
-
你不使用
forEach。你改用map。
标签: angularjs promise angular-promise q