angularjs - Angular resource $save has no push method -
in angular i've got following factory:
.factory('user', function($resource){ return $resource( '/users',//url {},//params defaults { 'save': {method: 'post', isarray: true } }//actions ) ; }) and in controller try save new resource so:
$scope.newuser = new user() ; $scope.newuser.name = $scope.newuserform.name ; $scope.newuser.email = $scope.newuserform.email ; $scope.newuser.$save() ; i array server looking that:
[ {id: 12, username: "adfsdf", email: "sadfsf@sdf.com" } ]
but somehow still , error in console:
typeerror: object # has no method 'push'
any idea i'm missing something?
thanks
seems me, user-resource @ client not array , thats why missing push-method.
'save': {method: 'post', isarray: true } //<---- array. $scope.newuser = new user() ; <-- create $scope.newuser.name = $scope.newuserform.name ; <--- put data $scope.newuser.email = $scope.newuserform.email now user looks like:
{ name:"somename", email:"some@email.com" } so no array. when server responds, angular trys push answer "array" matter of fact, not array.
so recommend leave "isarray:true" out, because 1 user not array. there not collection of users.
i don't know, how angular responds server response, when presented array-style, try it.
Comments
Post a Comment