0

When I debug my Angular application in Chrome I can see that some values are represented as "Resource". Each "Resource" has following values:

  • $$hashKey
  • Disabled
  • Group
  • Selected
  • Text
  • Value
  • __proto__

__proto__ is a "Resource" too and contains some functions, like $delete, $get, $query, $remove and $save. This gives me a cue it is somehow connected with Angular's $resource service.

Is this just a result of querying a web service using $resource service? If yes - can we create these objects (if "Resource" is an object) without querying service? On the other hand - can we retrieve data from services without this "Resource" overhead, just as plain data, without special processing?

Arkadiusz Kałkus
  • 17,101
  • 19
  • 69
  • 108
  • 1
    http://stackoverflow.com/questions/18826320/what-is-the-hashkey-added-to-my-json-stringify-result –  Feb 11 '16 at 10:21

1 Answers1

1

It indicates that the object was instantiated by Resource constructor. It is used internally by $resource service and isn't intended to be used outside of it, but it can - e.g. for testing purposes,

var Resource = $resource().prototype.constructor;
expect(someObj instanceof Resource).toBe(true);

On the other hand - can we retrieve data from services without this "Resource" overhead, just as plain data, without special processing?

$resource is a conventional solution for RESTful interactions in Angular. If the one considers it an 'overhead' and feels like its job can be done better than that, this wheel can be re-invented with $http (which $resource essentially uses to do what it does).

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • Thank you for your answer. It's good explanation. I just wanted to add I didn't mean $resource is overhead, but this additional fields returned by its get method. I thought maybe I use $resource wrong if mentioned fields exist in a result. As long as it is expected behavior and proper usage of $resource service I'm okay with it. – Arkadiusz Kałkus Feb 11 '16 at 12:58