Mittwoch, 18. Mai, 2016
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Finishing Angular TODO application and deploying to production 125<br />
31 $location.path('todos/' + $scope.todo._id);<br />
32 }, function(errorResponse) {<br />
33 $scope.error = errorResponse.data.message;<br />
34 });<br />
35 };<br />
36<br />
37 $scope.delete = function(todo) {<br />
38 if (todo) {<br />
39 todo.$remove(function() {<br />
40 for (var i in $scope.todos) {<br />
41 if ($scope.todos[i] === todo) {<br />
42 $scope.todos.splice(i, 1);<br />
43 }<br />
44 }<br />
45 });<br />
46 } else {<br />
47 $scope.todo.$remove(function() {<br />
48 $location.path('todos');<br />
49 });<br />
50 }<br />
51 };<br />
52 }<br />
53 ]);<br />
In this mumbo jumbo we’re injecting four services ($routeParams, $location, Authentication and<br />
Todos), and we have various functions defined on the scope object (which basically do what their<br />
names suggest). A note on the create function is that title and comment field will be provided via<br />
the form that we’ll create shortly now, in the Viewssection. Also, the delete function figures out<br />
whether the user is deleting an todo from a list or directly from the todo view.<br />
Views<br />
##### Create a todo view In the public/todos/views folder create a file create-todo.client.view.html<br />
with the following content: