Skip to content

Instantly share code, notes, and snippets.

@jaredwilli
Created April 27, 2013 08:30
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredwilli/5472340 to your computer and use it in GitHub Desktop.
Save jaredwilli/5472340 to your computer and use it in GitHub Desktop.
todoFactor and TodoCtrl modules for the angularFire TodoMVC example to show an alternative example for using angularFireCollection to sync data with a Firebase by using a Factory to do so. https://github.com/firebase/angularFire/issues/24
'use strict';
todomvc.controller('TodoCtrl', [ '$scope', 'todoFactory', 'filterFilter',
function OtherCtrl($scope, todoFactory, filterFilter) {
$scope.todos = todoFactory.getAllTodos('todos');
$scope.newTodo = '';
$scope.editedTodo = '';
$scope.addTodo = function() {
todoFactory.addTodo($scope.newTodo);
};
$scope.editTodo = function(todo) {
$scope.editedTodo = todo;
todoFactory.editTodo(todo);
};
$scope.doneEditing = function(todo) {
$scope.editedTodo = null;
if (!todo.title) {
$scope.removeTodo(todo);
}
};
$scope.removeTodo = function(todo) {
todoFactory.removeTodo(todo);
};
$scope.markAll = function(completed) {
$scope.todos.forEach(function (todo) {
todo.completed = completed;
});
};
}
]);
'use strict';
todomvc.factory('todoFactory', [ 'angularFireCollection',
function todoFactory(angularFireCollection) {
var url = 'https://angularFire.firebaseio-demo.com/todomvc';
return {
addTodo: function(newTodo) {
this.getAllTodos('todos').add({
title: newTodo,
completed: false
}, function() {
});
},
getAllTodos: function(path) {
var ref = angularFireCollection(url + '/' + path);
return ref;
},
editTodo: function(todo) {
this.getAllTodos('todos').update(todo);
},
removeTodo: function(todo) {
this.getAllTodos('todos').remove(todo);
}
};
}
]);
@benwells
Copy link

In this example, what exactly are you passing to the .remove(todo) method call in your todoFactory.js file? I am using your gist as a guide in my own application and am having trouble with the remove method. What does the remove method accept as an argument to uniquely identify the todo that you are trying to delete?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment