1

my case is, i want angularjs auto remove parameters defined in method :

My definition :

var service = $resource(apiConstant.baseUrl + '/website/:action', {port : ':8080'}, {
        save: {
            method: 'GET',
            isArray: false,
            params: {
                action: 'save', id: '@id', name: '@name', description: '@description',
                ownerId: '@ownerId', checked: '@checked'
            }
        }
    });

When i call service.save({id :3}), the actual URL generated is :

website/save?checked=undefined&description=undefined&id=3&name=undefined&ownerId=undefined

How can i tell angularjs auto remove those parameter not specified ?

I'm just want like this :

website/save?id=3

Thanks.

1 Answer 1

1

The only thing that you need to define in the params array would be action:'save' and that's it.  

params: {
            action: 'save'
 }

Then when we do save({id:3}) it would only call the desired url.

params array is used to bind parameters in url not in querystring. Also the @id syntax is used to map the parameter from the payload (object).

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.