7 |
10 |
33 |
34 |
35 | You have {{ todo.getRemaining().length }} of {{ todo.list.length }} items todo!
36 |
37 |
38 | You are super productive!
39 |
40 |
41 |
42 | `
43 | };
44 | }
45 |
46 | angular
47 | .module('app')
48 | .directive('todoApp', todoApp);
49 |
--------------------------------------------------------------------------------
/solution/js/todo.service.js:
--------------------------------------------------------------------------------
1 | function TodoService($http) {
2 |
3 | var API = '//jsonplaceholder.typicode.com/todos/';
4 |
5 | function create(todo) {
6 | return $http.post(API, todo).then(function (response) {
7 | return response.data;
8 | });
9 | }
10 | function retrieve() {
11 | return $http.get(API).then(function (response) {
12 | return response.data.splice(0, 10);
13 | });
14 | }
15 | function update(todo) {
16 | return $http.put(API + todo.id).then(function (response) {
17 | return response.data;
18 | });
19 | }
20 | function remove(todo) {
21 | return $http.delete(API + todo.id).then(function (response) {
22 | return response.data;
23 | });
24 | }
25 |
26 | return {
27 | create: create,
28 | retrieve: retrieve,
29 | update: update,
30 | remove: remove,
31 | };
32 | }
33 |
34 | angular
35 | .module('app')
36 | .factory('TodoService', TodoService);
37 |
--------------------------------------------------------------------------------
/solution/js/todoAutofocus.directive.js:
--------------------------------------------------------------------------------
1 | function todoAutofocus() {
2 | return {
3 | restrict: 'A',
4 | scope: false,
5 | link: function ($scope, $element, $attrs) {
6 | $scope.$watch($attrs.todoAutofocus, function (newValue, oldValue) {
7 | if (!newValue) {
8 | return;
9 | }
10 | setTimeout(function () {
11 | $element[0].focus();
12 | }, 0);
13 | });
14 | }
15 | };
16 | }
17 |
18 | angular
19 | .module('app')
20 | .directive('todoAutofocus', todoAutofocus);
21 |
--------------------------------------------------------------------------------