Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="myController">
<p ng-repeat="list in lists()">{{list.name}} {{list.done}}{{list.id}}</p>
<button ng-click="add()">Add New Item</button>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.name = 'Superhero';
}
myApp.service('toDoService', function(){
this.details = {
lists: [
{"name" : "abebe" ,"done":false, id: Date.now()}
]
}
this.getLists =function(){
var list = [
{"name" : "abebe" ,"done":false, id: Date.now()}
];
return list;
}
this.addList = function(item) {
this.details.lists.push(item)
}
});
myApp.controller("myController", ['$scope','toDoService',
function($scope,toDoService){
$scope.lists = function() { return toDoService.details.lists };
$scope.add = function(){
// WHAT TO PUT HERE????
var newListItem = {"name" : "abebe" ,"done":false, id: Date.now()}
toDoService.addList(newListItem)
}
}]);