Created
September 25, 2014 18:12
-
-
Save gajus/91be0b363f711a261224 to your computer and use it in GitHub Desktop.
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
var todoApp, | |
model; | |
model = { | |
user: 'Adam', | |
items: [] | |
}; | |
todoApp = angular.module('todoApp', []); | |
todoApp.run(function ($http) { | |
$http.get('./todo.json').success(function (data) { | |
model.items = data; | |
}); | |
}); | |
todoApp.controller('TodoController', function ($scope) { | |
$scope.todo = model; | |
$scope.incompleteCount = function () { | |
return $scope.todo.items.filter(function (item) { | |
return !item.done; | |
}).length; | |
}; | |
$scope.warningLevel = function () { | |
return $scope.incompleteCount() > 2 ? 'warning' : 'success'; | |
}; | |
$scope.addNewItem = function (actionText) { | |
return $scope.todo.items.push({ | |
name: actionText, | |
done: false | |
}); | |
}; | |
}); | |
todoApp.filter('checkedItems', function () { | |
return function (items, showComplete) { | |
var resultItems = []; | |
angular.forEach(items, function (item) { | |
if (item.done === false || showComplete === true) { | |
resultItems.push(item); | |
} | |
}); | |
return resultItems; | |
}; | |
}); |
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
[{"name": "Get the book", "done": true}, {"name": "Finish reading the book", "done": false}, {"name": "Summarize the book", "done": false}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment