This commit is contained in:
Arti Zirk 2017-04-20 09:49:26 +03:00
parent d19caa9360
commit 3375a736ff
8 changed files with 72 additions and 12 deletions

View File

@ -1,6 +1,7 @@
(function () { (function () {
'use strict'; 'use strict';
var app = angular.module('app', ['ngRoute']);
})(); })();

View File

@ -3,8 +3,18 @@
angular.module('app').controller('DetailsCtrl', Ctrl); 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');
}
} }
})(); })();

View File

@ -0,0 +1,3 @@
Title: {{ vm.item.title }} <br>
Time: {{ vm.item.added | date: "HH:mm"}}
<button ng-click="vm.back()">Back</button>

View File

@ -3,8 +3,36 @@
angular.module('app').controller('ListCtrl', Ctrl); 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 = '';
}
} }
})(); })();

View File

@ -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>

View File

@ -17,4 +17,4 @@
} }
})(); })();

View File

@ -1,14 +1,14 @@
{ {
"tasks": [ "tasks": [
{ {
"title": "Call Jill", "title": "sadfasdf",
"added": "2017-03-13T09:46:46.127Z", "done": false,
"_id": 1 "_id": 5
}, },
{ {
"title": "Write to John", "title": "asdf",
"added": "2017-03-13T10:09:38.867Z", "done": false,
"_id": 4 "_id": 6
} }
] ]
} }

View File

@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html lang="et"> <html lang="et" ng-app="app">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Ng1</title> <title>Ng1</title>
@ -9,13 +9,22 @@
<style type="text/css"> <style type="text/css">
.ng-cloak { display: none } .ng-cloak { display: none }
.done { text-decoration: line-through } .done { text-decoration: line-through }
.vertical {
display: block;
flex-direction: column;
}
</style> </style>
</head> </head>
<body> <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.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> </body>
</html> </html>