starting state
This commit is contained in:
parent
a894f852a6
commit
8af01584e3
@ -1,6 +1,6 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('app', ['ngRoute']);
|
||||
|
||||
})();
|
||||
|
||||
|
@ -3,23 +3,7 @@
|
||||
|
||||
angular.module('app').controller('DetailsCtrl', Ctrl);
|
||||
|
||||
function Ctrl($http, $routeParams, $location) {
|
||||
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');
|
||||
}
|
||||
function Ctrl() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -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>
|
@ -3,39 +3,9 @@
|
||||
|
||||
angular.module('app').controller('ListCtrl', Ctrl);
|
||||
|
||||
function Ctrl($http, modalService) {
|
||||
var vm = this;
|
||||
vm.tasks = [];
|
||||
vm.newTitle = '';
|
||||
function Ctrl() {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
|
@ -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>
|
||||
|
10
index.html
10
index.html
@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="et" ng-app="app">
|
||||
<html lang="et">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ng1</title>
|
||||
@ -13,15 +13,9 @@
|
||||
</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