Commit 42c1985d authored by Christoph Burgdorf's avatar Christoph Burgdorf

added localStorage functionality

parent 713a1a8a
......@@ -41,6 +41,7 @@
<div id="credits">
Created by <a href="http://twitter.com/cburgdorf">Christoph Burgdorf</a>.
</div>
<script src="js/libs/json2.js"></script>
<script src="js/booter.js"></script>
<script src="js/libs/angular/angular.min.js" ng:autobind></script>
<script src="js/controllers.js"></script>
......
......@@ -5,6 +5,26 @@ App.Controllers.TodoController = function () {
self.newTodo = "";
var retrieveStore = function() {
var store = localStorage.getItem('todo-angularjs');
return ( store && JSON.parse( store ) ) || [];
};
var updateStore = function() {
var isEditing = angular.Array.count(self.todos, function(x) {
return x.editing;
});
if (!isEditing){
localStorage.setItem('todo-angularjs', JSON.stringify(self.todos));
}
};
//not sure if its intended to do so. However, we need a hook to update the store
//whenever angular changes any properties
self.$watch(updateStore);
self.todos = retrieveStore();
self.addTodo = function() {
if (self.newTodo.trim().length === 0) return;
......@@ -37,8 +57,6 @@ App.Controllers.TodoController = function () {
angular.Array.remove(self.todos, todo);
};
self.todos = [];
var countTodos = function(done) {
return function() {
return angular.Array.count(self.todos, function(x) {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment