1

When I write a custom action $resource like this:

getEntityResource(): ng.resource.IResourceClass<IEntityResource> {


       let addAction: ng.resource.IActionDescriptor = {
            method: 'POST',
            url: 'http://localhost:8085/api/entity/add'
        }
        return <ng.resource.IResourceClass<IEntityResource>>
        this.$resource("http://localhost:8085/api/entity/:entityId", { id: '@id' },  {
          add: addAction,  
        });

and call it from the controller like this:

this.$mdDialog.hide(this.dataService
            .getEntityResource()
            .add(this.entity,
            () => this.$state.reload()
        ));

the call is sending like this:

Request URL:http://localhost:8085/api/entity/add?id=0

The webApi action is accepting entity object as parameter not an id:

[HttpPost]
public Entity Add(Entity entity)

The problem is that it sends the post request with a string parameter (?id=0) and not JSON object.

What am I missing?

Thank you.

2
  • are you getting any error? Whats the problem? Commented May 17, 2016 at 17:09
  • It's sending a query string /add?id=0 not a JSON object. Commented May 17, 2016 at 17:14

1 Answer 1

1

Take a look at $resource.

Your problem is, that you pass the data as second parameter. To pass the data as a JSON object you must do the following:

$resource("http://localhost:8085/api/entity/:entityId", 
     {},  
     {params: {id: '@id'}...}
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.