How Can I Get The Url From An Ng-resource?
How can I get the url (and params) from an ng-resource? And if that is not possible how can I create a wrapper or extend ng-resource so I get this functionality? Update: I want to
Solution 1:
Maybe the following will be of use. Since you have explicit control of the URL being passed into $resource, I assume you can transform the response to provide the function you desire. It is by no means clean, but does appear functional.
var resource;
resource = $resource('/foo/bar',
{
id: 1
}, {
get: {
method: 'GET',
transformResponse: function(data) {
data = angular.fromJson(data);
data.getUrl = function() {
return'/foo/bar';
};
returndata;
}
}
}
);
Solution 2:
It looks like NgResource stores all the internal variables and URLs inside its own scope, making it impossible to access them from the outside.
What you could do is to extend your $resource
with additional information that you provide. Using this method you can have your URL (or any property) alongside your resource.
myResource = angular.extend(
$resource('localhost/foo/bar'),
{
getUrl: function() { return'localhost/foo/bar'; }
}
);
myResource.getUrl() // returns localhost/foo/bar
Post a Comment for "How Can I Get The Url From An Ng-resource?"