Created
April 27, 2013 08:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; | |
}); | |
}; | |
} | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); | |
} | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?