resource factory:
.factory('workerrepository', function($resource){ return $resource('workers/:id', {id:'@id'}); })
controller:
.controller('listcontroller', function($scope, workerrepository){ var workers = workerrepository.query(function(){ $scope.workers = workers; }); $scope.worker = {namesurname: 'peter', email: "test@gmail.com", phone: 600100200}; $scope.add = function() { var worker = new workerrepository(this.worker); worker.$save(); }; })
when $scope.add
method executed script throws typeerror: object #<g> has no method 'push'
error. if understand correctly $resource
, $save
method default provides 'save': {method:'post'},
there no isarray: true
. why getting error?
apparently, error lied within backend rest controller (thanks hint @stewie!) - didn't linked post method action, $save()
method invoking action responsible query()
, indeed returns array of objects.
was:
query() -> /workers -> return array of workers save() -> post /workers -> return array of workers
after backend controller refactor:
query() -> /workers -> return array of workers save() -> post /workers -> return created worker
Comments
Post a Comment