Reputation: 12972
I'm working with a PhP interface. I must interact with this interface to save some data. For instance, to save a Customer, the PhP service wants the data through a POST request in this form
I tried to create an AngularJS service to do that:
angular.module("app").factory("SaveCustomer", ["$resource",
function($resource){
return $resource("/services/customers/post/",
{
customer[customer_name]:'@name',
customer[customer_code]:'@code',
customer[customer_is_visible]:'@visibility',
dtsave:'true'
},
{
save: {
method:'POST'
}
});
}]);
The problem is about the parameters name. Angular doesn't like the square bracket and it says: "Expected : but found [ in customer[custom ..." Can I achieve this task or do I have to modify the PhP interface to interact with? (note that the interface has not been created by me). Thank you.
EDIT: I call the service this way:
SaveCustomer.save({name:customerName, code:customerCode, visibility:customerIsVisible});
Upvotes: 0
Views: 279
Reputation: 9080
I think you don't need to define anything in default parameters in $resource object, this code should work (I think so)
angular.module("app").factory("SaveCustomer", ["$resource",
function($resource){
return $resource("/services/customers/post/",
{
dtsave:'true'
},
{
save: {
method:'POST'
}
}
);
}
]);
And you can call it:
SaveCustomer.save({customer: {customer_name:customerName, customer_code:customerCode, customer_is_visible:customerIsVisible}});
Upvotes: 1
Reputation: 8083
Try turning customer
into an object:
angular.module("app").factory("SaveCustomer", ["$resource",
function($resource){
return $resource("/services/customers/post/",
{
customer: {
customer_name: '@name',
customer_code:'@code',
customer_is_visible:'@visibility'
},
dtsave:'true'
},
{
save: {
method:'POST'
}
}
);
}
]);
Upvotes: 1