title: AngularJS $promise is undefined only inside a function
body: <p>I don't know how to describe my problem and how to ask what do I want? I experienced strange thing with <code>AngularJS</code>. I hope you will understand it by reading the below code snippet. Please inform me if I need to clarify some thing.</p>
  
  <p>In very short :
  The same thing is <code>working</code> and <code>not-working</code>.</p>
  
  <pre><code>(function(){
  
      angular.module('app', ['ngResource'])
  
      .factory('Post', function($resource){
  
          return $resource('/user/:userId/posts/:id', {'userId':'@creator','id':'@_id'}, {
              update : {method:'PUT'}
          });
  
      })
  
      .controller('PostController', 
      ["$scope", "Post",
      function($scope, Post){
  
          $scope.updatePost = function(data, params) {
                      //When I call this method 
              //This raises error that says:
              //Post.update(...).$promise is undefined
              Post.update(params, data).$promise.then(function(res){
                  console.log(res);
              });
          }
  
  
          //This is working
          Post.update({userId:'me', id:1}, {content:'Some modified content.'}).$promise.then(function(res){
              console.log(res);
          });
  
      }]);
  
  })();
  </code></pre>
  
  <p><strong>UPDATE</strong>
  Below is a log for both <code>working</code> and <code>not-working</code> things : </p>
  
  <p>When working  - console.log(Post.update(...)) results :  </p>
  
  <pre><code>$promise
      Object { then=function(), catch=function(), finally=function()}
  
  $resolved
      true
  
  content
      "Some modified Content"
  
  $delete
      function()
  
  $get
      function()
  
  $query
      function()
  
  $remove
      function()
  
  $save
      function()
  
  $update
      function()
  
  __proto__
      b { $get=function(), $save=function(), $query=function(), more...}
  </code></pre>
  
  <p>When working -  console.log(Post.update(...)) results :  </p>
  
  <pre><code>catch
      function()
  
  finally
      function()
  
  then
      function()
  </code></pre>