11

I'm trying to add a simple method on an angular resource, basically like this:

/api/resource/:id/archive

If I do it just like this:

angular.module('myApp')
.factory('api', function($resource) {
    var api = {
        messages: $resource('/api/messages/:id', {id: '@id'}
        , {
            archive: {
                method: 'PUT'
                , params: {id: '@id'}
                , url: '/api/messages/:id/archive'
            }
        }
    return api;
})
.controller('myCtrl', function(api) {
    // once I get messages and do stuff...
    $scope.archive = function(msg) {
        api.messages.archive({id: msg._id}, successHandler, failureHandler);
    }
});

It doesn't work, I get a simple PUT (*/api/messages/{id}*). I tried it with another param.

In factory:

....
archive: {
    method: 'PUT'
    , params: {id: '@id', action: '@action'}
    , url: '/api/messages/:id/:action'
....

In controller:

api.messages.archive({id: msg._id, action: 'archive'} ...)

I get the second param as a query param, instead as part of the url.

1 Answer 1

11

Well, after I typed the question, I saw I'm not using the latest angular. Angular 1.2.0 has this working.

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.