angularjs-resource

Angular 1.0.8 $resource with multiple optional get parameters

£可爱£侵袭症+ 提交于 2019-12-03 07:17:09
问题 My Student ulr looks like this: var Student = $resource('/app/student/:studentid:courseId', {studentid:'@id',courseId:'@cid'} ); When I call it without parameters I would like the url be /app/student/ (works) var names=Student.query( function(){ deferred.resolve(names); } ); When I call it with studentid I would like the url be /app/student/?id=88 (works) Student.get({"id":id}, function(data){ deferred.resolve(data); } ); When I call with courseid only I would like the url be /app/student/

Get response header in then() function of a ngResource object's $promise property after resource resolved?

我与影子孤独终老i 提交于 2019-12-03 06:06:45
I'm willing to retrieve the response header of a resource request, cause I've put pagination information and something else in it rather than the response body, to make the REST api clear. Though we can get it from the success / error callback like below: Object.get({type:'foo'}, function(value, responseHeaders){ var headers = responseHeaders(); }); Where 'Object' is my resource factory service. Further, when I'm trying to make the route change after required resources resolved, I've tried this: .when('/list', { templateUrl: 'partials/list.html', controller: 'ListCtrl', // wait for the

Angular 1.0.8 $resource with multiple optional get parameters

情到浓时终转凉″ 提交于 2019-12-02 20:51:34
My Student ulr looks like this: var Student = $resource('/app/student/:studentid:courseId', {studentid:'@id',courseId:'@cid'} ); When I call it without parameters I would like the url be /app/student/ (works) var names=Student.query( function(){ deferred.resolve(names); } ); When I call it with studentid I would like the url be /app/student/?id=88 (works) Student.get({"id":id}, function(data){ deferred.resolve(data); } ); When I call with courseid only I would like the url be /app/student/?courseid=99 (doesnt) Student.query({courseId:cId}, function(data){ deferred.resolve(data); } ); Instead I

Angularjs $resource Cache

早过忘川 提交于 2019-12-02 18:58:15
问题 I have a more generic implementation of $resource as "Datarepository" factory in my application and all the REST API calls calls this factory to do the "REST" operation myapp.factory('DataRepository', function ($resource) { var resourceFactory = function (url) { return $resource(url, {}, { update: { method: 'PUT' } } ); } return { invokeAPI: resourceFactory } }); A sample call to the repository get method looks like this DataRepository.invokeAPI(myappURL).get(); For a specific scenario alone,

Angular JS success callback

余生长醉 提交于 2019-12-02 17:43:45
问题 I m reaching out to you to get assistance on the $promise issue with AngularJS. Here is the documentation information on $resource and it will be applicable to $http as well link Having said that, I m trying to make an API call and on success want to perform callback action. Since the operation takes place asynchronously, callback action takes place even before the API call gets completed. This leads to incorrect data reflection. Here is the simple get example, using $resource and $http. In

Angular JS success callback

风流意气都作罢 提交于 2019-12-02 08:39:17
I m reaching out to you to get assistance on the $promise issue with AngularJS. Here is the documentation information on $resource and it will be applicable to $http as well link Having said that, I m trying to make an API call and on success want to perform callback action. Since the operation takes place asynchronously, callback action takes place even before the API call gets completed. This leads to incorrect data reflection. Here is the simple get example, using $resource and $http. In both the cases the actual expectation is that console log should show the actual data but it shows the

How do I not send url template parameters with request body in angular?

ぃ、小莉子 提交于 2019-11-30 17:23:17
Suppose I have a resource set up like this: resource = $resource( "http://foo.com/service/:type/:id", {}, {save: {method:'PUT', params: {type:'@type', id: '@id'}}} ); resource.save({type:'user', id:14, name:'Bob Dole'}); Is there any way I can prevent type and id from being submitted as part of the request body, and just send name in the PUT payload? I don't control the API I am submitting to, and it seems to not like the extra parameters I am sending it. Thanks! Update - 10/25/13 - 13:38 The documentation for resource says this: If the parameter value is prefixed with @ then the value of that

How do I not send url template parameters with request body in angular?

孤街醉人 提交于 2019-11-30 00:30:29
问题 Suppose I have a resource set up like this: resource = $resource( "http://foo.com/service/:type/:id", {}, {save: {method:'PUT', params: {type:'@type', id: '@id'}}} ); resource.save({type:'user', id:14, name:'Bob Dole'}); Is there any way I can prevent type and id from being submitted as part of the request body, and just send name in the PUT payload? I don't control the API I am submitting to, and it seems to not like the extra parameters I am sending it. Thanks! Update - 10/25/13 - 13:38 The

Invalidate $resource Cache After Post Request

让人想犯罪 __ 提交于 2019-11-30 00:17:28
I am using $resource and caching the results of get requests. My problem is that, after post requests, the cache is not being invalidated. Here is the return value from the service: return $resource('http://url.com/api/url/:id', {}, { 'query' : { method : 'GET', isArray:true, cache : true }, 'get' : { method : 'GET', cache : false } }) Here is the save method I am using inside my controller. As you can see, I'm using the callback on the post request to recalculate the query/list of nouns. var newNoun = new Noun($scope.noun); newNoun.$save(function(x) { $scope.nouns = Noun.query(); }); I would

How can I extend the constructor of an AngularJS resource ($resource)?

折月煮酒 提交于 2019-11-29 22:33:16
I have a model, defined using $resource , that I am successfully loading. Each loaded instance is, as promised, an instance of the class I defined. (The example below is from the Angular docs. In it, User.get results in an object that is an instanceof User .) var User = $resource('/user/:userId', {userId:'@id'}); However, imagine each User comes over the wire like this: { "username": "Bob", "preferences": [ { "id": 1, "title": "foo", "value": false } ] } I defined a Preference factory that adds valuable methods to Preference objects. But when a User loads, those preferences aren’t Preference s