资源工厂:
.factory('WorkerRepository', function($resource){
return $resource('workers/:id', {id:'@id'});
})
控制器:
.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();
};
})
执行方法时$scope.add
,脚本会引发TypeError: Object #<g> has no method 'push'
错误。如果我理解正确$resource
,$save
方法默认只提供'save': {method:'POST'},
所以没有isArray: true
。那么为什么我会收到这个错误?