I can't figure out why I'm getting an
Cannot read property 'finally' of undefined error here..
$scope.saveToDos = function(){
console.log("Save to do was pressed.")
var filteredTodos = $scope.todos.filter(function(todo){
if(todo.edited){
return todo
}
})
console.log("There are " + filteredTodos.length + " edited todos")
dataService.saveToDos(filteredTodos)
.finally($scope.resetTodoState())
}
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!");
})
}
You aren't returning anything from saveToDos()
, so the return value is by default undefined
.
You probably wanted to return $q.all(...