title: angularjs: after ng-model $scope.resource looks not the same
body: <p>I have two functions in my Controller. </p>
  
  <ul>
  <li>The <code>showEditScreen</code> function which actually loads a user record over
  <code>$resource.get</code>. </li>
  <li>The <code>updateUserDetails</code> function which should update the user.</li>
  </ul>
  
  <p>In the <code>showEditScreen</code> function everything is working. The user details are parsed over json and when looking at the <code>$scope.user</code> object functions like <code>$get</code>, <code>$post</code>, <code>$update</code> are present.</p>
  
  <p>When looking at the same (also unmodified) object in the <code>updateUserDetails</code> function the object has changed and all the functions like <code>$get</code>, <code>$post</code>, <code>$update</code> and so on are missing.</p>
  
  <p>This is a really weird behavior. Does anybody have an explanation for this?</p>
  
  <p>When I use http.put i can save the object by the way. </p>
  
  <p><strong>console.log($scope.user) output in showEditScreen() function</strong></p>
  
  <pre><code>Resource {$get: function, $save: function, $query: function, $remove: function, $delete:      function…}
  firstName: "Mista"
  id: "d419375a-ba0b-4177-93cf-842e2c3e046e"
  lastName: "BlaaahBlaaah1"
  password: "bla"
  roles: Array[2]
  username: "blabla1"
  __proto__: Resource
  </code></pre>
  
  <p><strong>console.log($scope.user) in updateUserDetails() function:</strong></p>
  
  <pre><code>Resource {id: "d419375a-ba0b-4177-93cf-842e2c3e046e", firstName: "Mista", lastName: "BlaaahBlaaah1", username: "blabla1", password: "bla"…}
  firstName: "Mista"
  id: "d419375a-ba0b-4177-93cf-842e2c3e046e"
  lastName: "BlaaahBlaaah1"
  password: "bla"
  roles: Array[2]
  username: "blabla1"
  __proto__: Resource
  </code></pre>
  
  <p><strong>When executing $scope.user.$update() in updateUserDetails() function:</strong></p>
  
  <pre><code>POST http://localhost:8080/api/user/.json 405 (Request method 'POST' not supported)      angular.js:9120
  (anonymous function) angular.js:9120
  sendReq angular.js:8977
  $http angular.js:8768
  Resource.(anonymous function) angular-resource.js:385
  Resource.(anonymous function) angular-resource.js:431
  UserCtrl.$scope.updateUserDetails controllers.js:37
  (anonymous function) angular.js:6212
  (anonymous function) angular.js:12751
  Scope.$eval angular.js:7905
  Scope.$apply angular.js:7985
  $delegate.__proto__.$apply index.html:500
  (anonymous function) angular.js:12750
  (anonymous function) angular.js:1928
  forEach angular.js:110
  eventHandler angular.js:1927
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div id="user_list" class="listview_list"&gt;
  &lt;div id="user_row" class="listview_row" ng-repeat="user in users"&gt;
      &lt;div id="user_username" class="listview_column"&gt;&lt;span class="listview_fat"&gt;   {{user.username}}&lt;/span&gt;&lt;/div&gt;
      &lt;div id="user_firstname" class="listview_column"&gt;{{user.firstName}}&lt;/div&gt;
      &lt;div id="user_lastname" class="listview_column"&gt;{{user.lastName}}&lt;/div&gt;
      &lt;button class="listview_row_button" ng-click="showEditScreen(user.id)"&gt;Edit&lt;/button&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="user_edit" class="edit_form" ng-show="userEditScreenIsVisible"&gt;
  &lt;form name="edit_user"&gt;
      &lt;label&gt;Username&lt;/label&gt;&lt;br/&gt;
      &lt;input name="username" ng-model="user.username" required/&gt;&lt;br/&gt;
      &lt;label&gt;Firstname&lt;/label&gt;&lt;br/&gt;
      &lt;input name="firstName" ng-model="user.firstName" required/&gt;&lt;br/&gt;
      &lt;label&gt;Lastname&lt;/label&gt;&lt;br/&gt;
      &lt;input name="lastName" ng-model="user.lastName" required/&gt;&lt;br/&gt;
      &lt;button class="button" ng-click="hideEditScreen()"&gt;Close&lt;/button&gt;
      &lt;button class="button" ng-click="updateUserDetails()"&gt;Update&lt;/button&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>/*
  * Controller to display and manipulate users.
  */
  function UserCtrl($scope, $http, Users, User) {
  // set edit screen to invisible by default
  $scope.userEditScreenIsVisible = false;
  
  // set new screen to invisible by default
  $scope.userNewScreenIsVisible = false;
  
  // display list with users
  Users.query(
      {}, //params
      function (data) { //success
          $scope.users = data.data;
      },
      function (data) { //failure
          console.log("Error occurred while getting list of users");
      });
  
  // show edit screen if edit button is clicked
  $scope.showEditScreen = function(id) {
      $scope.user = User.get({userId: id});
      console.log($scope.user);
      $scope.userEditScreenIsVisible = true;
  }
  
  // hide edit screen if close button is clicked
  $scope.hideEditScreen = function() {
      $scope.userEditScreenIsVisible = false;
  }
  
  $scope.updateUserDetails = function() {
      console.log($scope.user);
      $scope.user.$update();
      //$http.put("http://localhost:8080/api/user/" + $scope.user.id + ".json", $scope.user);
  }
  
  // show new screen if add button is clicked
  $scope.showNewScreen = function() {
      $scope.userNewScreenIsVisible = true;
  }
  }
  </code></pre>
  
  <p><strong>Service:</strong></p>
  
  <pre><code>angular.module('user.services', ['ngResource']).
  factory('Users', function($resource) {
      return $resource('http://localhost\\:8080/api/user/all.json', {}, {
          query: {method:'GET', params:{}, isArray:false}
      });
  }).
  factory('User', function($resource){
      return $resource('http://localhost\\:8080/api/user/:userId.json', {}, {
         get: {method:'GET'},
         update: {method:'PUT'}
      });
  })
  </code></pre>
  
  <p><strong>Issue solved!!!!</strong></p>
  
  <p>Service:</p>
  
  <pre><code>// User Service
  angular.module('user.services', ['ngResource']).
  factory('User', function($resource){
      return $resource('/api/user/:userId', {userId: '@id'}, {
         query: {method: 'GET', headers: [{'Content-Type': 'application/json'}, {'Accept'  : 'application/json'}]},
         get: {method:'GET', headers: [{'Content-Type': 'application/json'}, {'Accept' :  'application/json'}]},
         update: {method:'PUT', headers: [{'Content-Type': 'application/json'}, {'Accept'  : 'application/json'}]}
      });
  })
  </code></pre>