如何异步执行此操作,请打印console.log(“打印此文件,完成所有循环后完成”)如何等待/完成每个循环的多个插入函数?
我已经forEach里面forEach。
InsertService不返回任何值,我只是想在这里插入。
我不知道如何申请$ q和$ q.all。请帮助。
angular.forEach(MAIN, function (value, key) {
//#1
SelectService1.SelectID(value.id).then(function (res) {
angular.forEach(res, function (value, key) {
InsertService1.Insert(value).then(function (res) {
console.log("NEW INSERTED Service 1!");
},
function (err) {
});
});
},
function (err) {
});
//#2
SelectService2.SelectID(value.id).then(function (res) {
angular.forEach(res, function (value, key) {
InsertService2.Insert(value).then(function (res) {
console.log("NEW INSERTED Service 2!");
},
function (err) {
});
});
},
function (err) {
});
//#3
SelectService3.SelectID(value.id).then(function (res) {
angular.forEach(res, function (value, key) {
InsertService3.Insert(value).then(function (res) {
console.log("NEW INSERTED Service 3!");
},
function (err) {
});
});
},
function (err) {
});
});
//
console.log("PRINT THIS, AFTER ALL LOOP IS DONE");
}
myInsert不返回任何值,我只是想插入和插入和循环后,我想打印,“所有已完成” –
先生我编辑我的问题请参阅。 –
@PauloDelaCruz如果Insert没有返回值,则不能使用.then()。你确定它没有?它看起来像它现在所谓的selectID,它需要返回一个承诺。 – rjustin