sohail khalil
sohail khalil

Reputation: 770

.$save not working in angular

Factory

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'                                                                                  }
    });
  }
});

Controller

$scope.shipment = new Shipment($scope.shipment)
$scope.shipment.$save(function() {
  debugger
});

It gives me this error:

$scope.shipment.$save is not a function

query and get are working fine.

Upvotes: 1

Views: 395

Answers (2)

Muaaz Rafi
Muaaz Rafi

Reputation: 1489

Declare your factory like below.

do ->
  angular.module('yourModule').factory('prefixShipment', ['$resource', function($resource){
    $resource(basePath + "shipments/:id", { id: '@_id' }, {
      update: {
        method: 'PUT'
      }
    })
  }])

Now for saving use the below snippet.

shipment = new prefixShipment({shipment: shipment})
shipment.save({},function(response){
    //your code      
})

Forget record.

prefixShipment.get({ id: $stateParams.shipment_id } , function(data{
  $scope.booking = data.booking
});

Upvotes: 1

kwoktung
kwoktung

Reputation: 612

don't use Constructor !! try this:

$scope.shipment = Shipment($scope.shipment)
$scope.shipment.$save(function() {
  debugger
});

Upvotes: 0

Related Questions