工厂
app.factory('Shipment', function($resource) {
return function(auth_token){
return $resource(basePath + "shipments/:id", { id: '@_id' }, {
query: { method: 'GET', params: {auth_token: auth_token}, isArray:true },
update: { method: 'PUT' }
});
}
});
控制器
$scope.shipment = new Shipment($scope.shipment)
$scope.shipment.$save(function() {
debugger
});
它给出了这个错误:
$scope.shipment.$save is not a function
query和get运行得很好。
发布于 2016-08-04 17:54:12
如下所示声明你的工厂。
do ->
angular.module('yourModule').factory('prefixShipment', ['$resource', function($resource){
$resource(basePath + "shipments/:id", { id: '@_id' }, {
update: {
method: 'PUT'
}
})
}])
现在为了保存,请使用下面的代码片段。
shipment = new prefixShipment({shipment: shipment})
shipment.save({},function(response){
//your code
})
忘了记录吧。
prefixShipment.get({ id: $stateParams.shipment_id } , function(data{
$scope.booking = data.booking
});
发布于 2016-08-04 17:55:29
不要使用构造函数!!试试这个:
$scope.shipment = Shipment($scope.shipment)
$scope.shipment.$save(function() {
debugger
});
https://stackoverflow.com/questions/38763888
复制相似问题