Search code examples
javascriptangularjsasynchronousangularjs-factoryangularjs-resource

How to use @id in $resource object in angularjs


I am using $resource in angularjs to call my rails api and when i call this route using angularjs $resource object like this

.factory('playlists',['$resource', function($resource) {
    return $resource("/events/:id/playlists", {id: "@id"},{
        query: {method: 'GET', isArray: true}
    })
}]);

I am calling this query method from controller like this

$scope.playlists = playlists.query();

It is actually calling only

/events/playlists

I don't know why :id is not replacing with proper event_id


Solution

  • To get that parameter reflect into the URL you need to pass that parameter while calling $resource get method

    playlists.get({ id: 1})