0
createQuestionDataAsync不返回數據。 flQuestion.create函數調用寫入mongodb集合的快速服務。問題被寫入並且值返回並存儲在「數據」中。我無法像典型的回調(err,data)那樣設置它,因爲迴應只返回一個值。也許我需要做出這個承諾?或者我可以保留一個回調一些修改?角度回調沒有將數據返回給角度承諾
angular.module( '應用')工廠( 'flQuestionCrud',函數($ HTTP,$ Q,$狀態,flQuestion){ 回報{ createNewQuestion:功能(newQuestionData){ 的console.log(」之前 - flQuestion.create「);
// Question Call Back Function
function questionCallBack(err, data){
if (err){
console.log("flQuestionCrud - Error " + err);
console.log("flQuestionCrud - Error Statement " + err);
return null;
//$state.go('questionCreate');
}else {
console.log("flQuestionCrud - Success " + data);
console.log("flQuestionCrud - Success Statement " + data.statement);
console.log("flQuestionCrud - Success Question id " + data._id);
return data;
//$state.go('questionUpdate');
}
}
// Try/catch
function createQuestionDataAsync(questionData, cb) {
console.log("flQuestionCrud - Before Call to create ")
flQuestion.create(questionData, function(data) {
console.log("flQuestionCrud - After Call to create ")
if (!data){
return cb("Error Creating Data");
//return null;
}
try {
console.log("flQuestionCrud - Try Section - Success " + data);
console.log("flQuestionCrud - Try Section - Success Statement " + data.statement);
console.log("flQuestionCrud - Try Section - Success Question id " + data._id);
}
catch (err) {
return cb("Error Creating Data");
//return null;
}
return cb(null,data);
//return data;
});
}
createQuestionDataAsync(newQuestionData,questionCallBack);