title: Promise on AngularJS resource save action
body: <p>I am currently working on a REST + AngularJS application.</p>
  
  <p>I have a little problem concerning promises on resource save action.</p>
  
  <p>My Factory:</p>
  
  <pre><code>App.factory('Course', function($resource) {
      var course = $resource('/AppServer/admin/courses/:courseId', {}, {});
  
      course.findAll = function() {
          return course.query();
      };
  
      course.findById = function(id) {
          return course.get({
              courseId : id
          });
  
      };
  
      course.saveCourse = function(course) {
          return course.$save();
      }
  
      return course;
  });
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>App.controller('CourseEditController', function($scope, $routeParams, $location, Course, FlashMessage) {
      // load course into edit form
      $scope.course = Course.findById($routeParams.courseId);
  
      // save edited course and print flash message
      $scope.saveCourse = function() {
          var savedCourse = Course.saveCourse($scope.course);
  
          savedCourse.$then(function(httpResponse) {
              FlashMessage.set("Die Änderungen am Kurs &lt;i&gt;" + savedCourse.title + "&lt;/i&gt; wurden erfolgreich gespeichert.");
              $location.path("/kurse/verwalten");
          });
      }
  }); 
  </code></pre>
  
  <p>Now the problem is, that I get the following exception:</p>
  
  <pre><code>TypeError: Cannot call method '$then' of undefined
  </code></pre>
  
  <p>The strange thing is that If I add the same then-callback to one of the finders (e.g. findById) everything works fine. But the return value of "return course.$save()" is undefined, compared to the return value of "return course.get({courseId:id});" which is "Object object".</p>
  
  <p>What I want is to set the FlashMessage when the save action was fully executed and not before that.</p>
  
  <p>Any ideas on this? The response from my REST service is correct. It returns the saved object.</p>
  
  <p>Greets
  Marc</p>