【发布时间】:2017-09-14 12:15:32
【问题描述】:
如何异步执行此操作,打印 console.log("PRINT THIS, AFTER ALL LOOP IS DONE")
我在 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");
}
【问题讨论】:
标签: angularjs sqlite insert promise angular-promise