starting state

This commit is contained in:
Märt Kalmo 2017-03-14 10:38:10 +02:00
parent a894f852a6
commit 8af01584e3
6 changed files with 6 additions and 71 deletions

View File

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

View File

@ -3,23 +3,7 @@
angular.module('app').controller('DetailsCtrl', Ctrl); angular.module('app').controller('DetailsCtrl', Ctrl);
function Ctrl($http, $routeParams, $location) { function Ctrl() {
var vm = this;
vm.task = {};
vm.back = back;
init();
function init() {
$http.get('api/tasks/' + $routeParams.id).then(function (result) {
vm.task = result.data;
});
}
function back() {
$location.path('/list');
}
} }

View File

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

View File

@ -3,39 +3,9 @@
angular.module('app').controller('ListCtrl', Ctrl); angular.module('app').controller('ListCtrl', Ctrl);
function Ctrl($http, modalService) { function Ctrl() {
var vm = this;
vm.tasks = [];
vm.newTitle = '';
vm.addTask = addTask;
vm.removeTask = removeTask;
init();
function init() {
$http.get('api/tasks').then(function (result) {
vm.tasks = result.data;
});
}
function addTask() {
var newTask = {
title: vm.newTitle,
added: new Date()
};
$http.post('api/tasks', newTask).then(init);
vm.newTitle = '';
}
function removeTask(id) {
modalService.confirm()
.then(function () {
return $http.delete('api/tasks/' + id);
}).then(init);
}
} }
})(); })();

View File

@ -1,9 +0,0 @@
<div data-ng-repeat="task in vm.tasks">
<span ng-class="{ done: task.done }" ><a href="#/details/{{ task._id }}" >{{ task.title }}</a></span>
<input type="checkbox" ng-model="task.done"/><a href ng-click="vm.removeTask(task._id)">X</a>
</div><br>
<input ng-model="vm.newTitle"/>
<button ng-click="vm.addTask(newTask)">Add task</button>

View File

@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html lang="et" ng-app="app"> <html lang="et">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Ng1</title> <title>Ng1</title>
@ -13,15 +13,9 @@
</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>