「終於」我想不出最後一線,我不知道爲什麼。 這個問題可以複製克隆的Git回購 https://github.com/Velua/To-Do-List無法讀取屬性未定義
this.saveToDos = function(todos){
var queue = [];
todos.forEach(function(todo){
var request;
if(!todo._id){
request = $http.post('/api/todos', todo);
} else{
request = $http.put('/api/todos/' + todo._id, todo).then(function(result){
todo = result.data.todo;
return todo
})
}
queue.push(request);
})
$q.all(queue).then(function(results){
console.log("I saved " + todos.length + " todos!");
})
}
謝謝!
是什麼'dataService.saveToDos'返回? – JJJ
'finally()'是一個保留關鍵字(函數);嘗試的一部分...終於趕上...。所以沒有嘗試阻止,最後會導致這樣的錯誤。 –
@KiranShakya如果它被用作關鍵字,那會是真的,但事實並非如此。 – JJJ