Finished
This commit is contained in:
parent
d19caa9360
commit
3375a736ff
@ -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>
|
12
data/db.json
12
data/db.json
@ -1,14 +1,14 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"title": "Call Jill",
|
||||
"added": "2017-03-13T09:46:46.127Z",
|
||||
"_id": 1
|
||||
"title": "sadfasdf",
|
||||
"done": false,
|
||||
"_id": 5
|
||||
},
|
||||
{
|
||||
"title": "Write to John",
|
||||
"added": "2017-03-13T10:09:38.867Z",
|
||||
"_id": 4
|
||||
"title": "asdf",
|
||||
"done": false,
|
||||
"_id": 6
|
||||
}
|
||||
]
|
||||
}
|
15
index.html
15
index.html
@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="et">
|
||||
<html lang="et" ng-app="app">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ng1</title>
|
||||
@ -9,13 +9,22 @@
|
||||
<style type="text/css">
|
||||
.ng-cloak { display: none }
|
||||
.done { text-decoration: line-through }
|
||||
.vertical {
|
||||
display: block;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<div ng-view></div>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.min.js"></script>
|
||||
<script src="app/app.js"></script>
|
||||
<script src="app/routes.js"></script>
|
||||
<script src="app/list.ctrl.js"></script>
|
||||
<script src="app/details.ctrl.js"></script>
|
||||
<script src="app/modal.srv.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user