Finished
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var app = angular.module('app', ['ngRoute']);
|
||||
|
||||
})();
|
||||
|
||||
|
||||
@@ -3,8 +3,18 @@
|
||||
|
||||
angular.module('app').controller('DetailsCtrl', Ctrl);
|
||||
|
||||
function Ctrl() {
|
||||
function Ctrl($http, $routeParams, $location) {
|
||||
var vm = this;
|
||||
vm.item = {};
|
||||
vm.back = back;
|
||||
|
||||
$http.get('api/tasks/'+$routeParams.id).then(function (resp) {
|
||||
vm.item = resp.data;
|
||||
});
|
||||
|
||||
function back() {
|
||||
$location.path('/list');
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Title: {{ vm.item.title }} <br>
|
||||
Time: {{ vm.item.added | date: "HH:mm"}}
|
||||
<button ng-click="vm.back()">Back</button>
|
||||
|
||||
@@ -3,8 +3,36 @@
|
||||
|
||||
angular.module('app').controller('ListCtrl', Ctrl);
|
||||
|
||||
function Ctrl() {
|
||||
function Ctrl($http, modalService) {
|
||||
var vm = this;
|
||||
|
||||
vm.items = [{ title: "hello", done: false }];
|
||||
vm.newItem = '';
|
||||
vm.addNew = addNew;
|
||||
vm.removeItem = removeItem;
|
||||
|
||||
pullItems();
|
||||
function pullItems() {
|
||||
$http.get('api/tasks').then(function(resp) {
|
||||
vm.items = resp.data;
|
||||
});
|
||||
};
|
||||
|
||||
function removeItem(id) {
|
||||
modalService.confirm()
|
||||
.then(function() {
|
||||
return $http.delete('api/tasks/'+id);
|
||||
}).then(pullItems);
|
||||
}
|
||||
|
||||
function addNew () {
|
||||
var item = {title:this.newItem, done:false};
|
||||
|
||||
$http.post('api/tasks', item).then(pullItems);
|
||||
|
||||
//this.items.push(item);
|
||||
vm.newItem = '';
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<div ng-repeat="item in vm.items">
|
||||
<span ng-class="{ done: item.done }">
|
||||
<a href="#/details/{{ item._id }}">{{ item.title }}</a>
|
||||
</span>
|
||||
<input type="checkbox" ng-model="item.done">
|
||||
<button ng-click="vm.removeItem(item._id)">X</button>
|
||||
</div>
|
||||
<input ng-model="vm.newItem">
|
||||
<button ng-click="vm.addNew()">Add new</button>
|
||||
|
||||
@@ -17,4 +17,4 @@
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user