notes-edit-controller.js 994 B

1234567891011121314151617181920212223242526272829303132333435
  1. angular.module('NoteWrangler').controller('NotesEditController', function($scope, $routeParams, Note, Category, Session) {
  2. // Without NgResource
  3. // Note.find($routeParams.id).success(function(noteData) {
  4. // $scope.note = noteData;
  5. // });
  6. Session.authenticate();
  7. // With NgResource
  8. $scope.note = Note.get({id: $routeParams.id})
  9. // Fetch the node types to use within the sorting menu
  10. Category.all().then(function(categoryData) {
  11. $scope.categories = categoryData;
  12. });
  13. $scope.updateNote = function(note) {
  14. $scope.errors = null;
  15. $scope.updating = true;
  16. // Without NgResource
  17. // Note.update(note).catch(function(noteData) {
  18. // $scope.errors = [noteData.data.error];
  19. // }).finally(function() {
  20. // $scope.updating = false;
  21. // });
  22. // With NgResource
  23. note.$update().catch(function(noteData) {
  24. $scope.errors = [noteData.data.error];
  25. }).finally(function() {
  26. $scope.updating = false;
  27. });
  28. };
  29. });