rethinkdb / rethinkdb-example-nodejs

137 stars 98 forks source link

Error in $scope.clearCompletedTodos project angular with promise #20

Closed Tilican closed 8 years ago

Tilican commented 8 years ago

Hello,

On your example todo with angular and promise, the clearCompletedTodos have a little mistake !

$scope.clearCompletedTodos = function () {
  $scope.todos = todos.filter(function (val) {
    return !val.completed;
  });
};

Angular don't know todos and todos are not delete from DB ...

Have to change this to

$scope.clearCompletedTodos = function () {
  var todos = $scope.todos.filter(function (val) {
    return val.completed;
  });
  for (var i = 0; i < todos.length; i++){
    $scope.removeTodo(todos[i]);
  }
};

Bye and thx for this example :+1:

danielmewes commented 8 years ago

Thanks for reporting the issue and for providing a patch.

@deontologician does this look like the right fix?

deontologician commented 8 years ago

It looks like this is from the todo-angular-express and todo-angular-express-promise directories getting out of sync. This issue is found in the promise example, but not in the other one.

In the non-promise version, we have:

$scope.clearCompletedTodos = function () {
  $scope.todos.forEach(function (todo) {
    if(todo.completed) {
      $scope.removeTodo(todo);
    }
  });
};

which is a little cleaner I think

deontologician commented 8 years ago

I went ahead and made the change in 6600248

deontologician commented 8 years ago

Thanks again @Tilican :)