<!DOCTYPE html>
<html>
<head>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore.js'></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/restangular/latest/restangular.js"></script>
<script src="script.js"></script>
</head>
<body data-ng-app='app'>
<div data-ng-controller='SomeController'>
<div>
{{someData}}
</div>
</div>
</body>
</html>
angular.module('app', ['restangular'])
.factory('SomeService', ['$q', 'Restangular', 'Utils',
function SomeService($q, Restangular, Utils) {
return {
getSomeData: function() {
var deferred = $q.defer();
Restangular.setBaseUrl(document.location.href);
Restangular.one('res.json').get().then(function(res) {
res.newlyAddedProp = 'I just added this prop';
res = Utils.sanitizeRestangularOne(res);
deferred.resolve(res);
});
return deferred.promise;
}
}
}
])
.factory('Utils', [
function Utils() {
return {
sanitizeRestangularOne: function(item) {
return _.omit(item, "route", "parentResource", "getList", "get", "post", "put", "remove", "head", "trace", "options", "patch",
"$get", "$save", "$query", "$remove", "$delete", "$put", "$post", "$head", "$trace", "$options", "$patch",
"$then", "$resolved", "restangularCollection", "customOperation", "customGET", "customPOST",
"customPUT", "customDELETE", "customGETLIST", "$getList", "$resolved", "restangularCollection", "one", "all", "doGET", "doPOST",
"doPUT", "doDELETE", "doGETLIST", "addRestangularMethod", "getRestangularUrl", "restangularEtag", "reqParams");
}
}
}
])
.controller('SomeController', ['$scope', 'SomeService',
function SomeController($scope, SomeService) {
SomeService.getSomeData().then(function(res) {
$scope.someData = res;
});
}
]);
{
"someKey": "someVal",
"someOtherKey": "someOtherVal"
}
Demonstration of the correct way to resolve/unproxy promises in 1.2rc3 angular