notes-create-controller.js 931 B

123456789101112131415161718192021222324252627282930313233
  1. angular.module('NoteWrangler').controller('NotesCreateController', function($scope, Note, Category, Session) {
  2. // redirect if a user is not logged in
  3. Session.authenticate();
  4. // Create a new blank note
  5. $scope.note = new Note();
  6. // Fetch the node types to use within the sorting menu
  7. Category.all().then(function(categoryData) {
  8. $scope.categories = categoryData;
  9. $scope.note.CategoryId = categoryData[0].id;
  10. });
  11. $scope.updateNote = function(note) {
  12. $scope.errors = null;
  13. $scope.updating = true;
  14. // Without NgResource
  15. // Note.create(note).catch(function(noteData) {
  16. // $scope.errors = [noteData.data.error];
  17. // }).finally(function() {
  18. // $scope.updating = false;
  19. // });
  20. // With NgResource
  21. note.$save().catch(function(noteData) {
  22. $scope.errors = [noteData.data.error];
  23. }).finally(function() {
  24. $scope.updating = false;
  25. });
  26. };
  27. });