I'm using $resource in angular to get json object and its structure is defined below
[
{
"id": 0,
"name": "Type1"
},
{
"id": 1,
"name": "Type 2"
}
]
after fetching the data .. console.log(jsonObject) gives me
[Resource, Resource, $promise: Object, $resolved: true]
How can I remove $promise & $resolved from the resulting object ? I tried angular.fromJson(json) but still I see that these objects still exist.
Please simply do this:
jsonObject.$promise = undefined; jsonObject.$resolved = undefined;
$promise and $resolved will not be removed but you will be able to do what you want.
Try to code something like this in your service:
And then something like this in your controller:
I'm looking for the same answer, but at this moment I know only this ugly hack:
To write a func like this:
and call it in every single query (ugly, yep):
I'll be happy if someone would teach me how to do it correctly
I'm facing the same issue. In fact, you simply have to use the same version of angular and angular-resource and it will work like a charm. Hope it helps !
Short answer : angular.fromJson(angular.toJson(resp)); This will remove all "angular specific" functions etc and will return you a clean data object.
Right, I've faced the same problem several times and always ended up using $http instead of $resource, however, today I decided to try and deal with this issue. I hope somebody will find this useful one day as well.
So, after you receive your object with $promise inside of it, what you do is just use
angular.copy(data)
, like so:After that, you will see that your
dataWithoutPromise
just contains the objects that you need, and $promise and $resolved are gone.