Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d3c50c8

Browse files
rodyhaddadbtford
authored andcommitted
feat($resource): allow props beginning with $ to be used on resources
BREAKING CHANGE: If you expected `$resource` to strip these types of properties before, you will have to manually do this yourself now.
1 parent c054288 commit d3c50c8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/ngResource/resource.js

+7
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ angular.module('ngResource', ['ng']).
493493
shallowClearAndCopy(value || {}, this);
494494
}
495495

496+
Resource.prototype.toJSON = function () {
497+
var data = extend({}, this);
498+
delete data.$promise;
499+
delete data.$resolved;
500+
return data;
501+
};
502+
496503
forEach(actions, function (action, name) {
497504
var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
498505

test/ngResource/resourceSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,20 @@ describe("resource", function() {
653653
expect(person2).toEqual(jasmine.any(Person));
654654
});
655655

656+
it('should not include $promise and $resolved when resource is toJson\'ed', function() {
657+
$httpBackend.expect('GET', '/CreditCard/123').respond({id: 123, number: '9876'});
658+
var cc = CreditCard.get({id: 123});
659+
$httpBackend.flush();
660+
661+
expect(cc.$promise).toBeDefined();
662+
expect(cc.$resolved).toBe(true);
663+
664+
var json = JSON.parse(angular.toJson(cc));
665+
expect(json.$promise).not.toBeDefined();
666+
expect(json.$resolved).not.toBeDefined();
667+
expect(json).toEqual({id: 123, number: '9876'});
668+
});
669+
656670
describe('promise api', function() {
657671

658672
var $rootScope;

0 commit comments

Comments
 (0)