Search code examples
javascriptangularjshttp-headersurl-parametersngresource

Post Params Not Sent to Server


I have a simple $resource factory.

.factory('Order', order)

order.$inject = ['$resource', "ApiEndpoint", "UserRecord"];

function order($resource, ApiEndpoint, UserRecord) {
  return $resource(ApiEndpoint.url + 'orders.json', {}, {
    create: {method: 'POST', url: ApiEndpoint.url + 'orders.json'}
  });
}

Here is the code I'm executing.

var params = {product_id: 32342, variant_id: 536341};

Order.create(params, function( resp ) {
  console.log("success");
});

When I run create the params are not going through. No params are passing. Why is this and how can I fix this?


Solution

  • I realized I'm missing a second argument, POST-DATA.

    Order.create(params, {}, function( resp ) {
      console.log("success");
    });