I'm currently using Angular $resource to make an api, and I would like to keep those results in a service rather than a controller because every time I call the controller the results get called again, and thus any changes that were made get deleted.
I have tried answers given in several SO articles including:
and
Angular Services/Factories with $resource
but neither of those have worked because I need the results stored in the service, but accessible for the controller.
Any help would be greatly appreciated.
Since Angular's Services/Factories are singletons, if you just put the value of the callback on the services variable, you'll be able to get it from anywhere. Sample:
It's nice to remember that $resource is perfoming an asynchronous request to backend, so it would be nice to guarantee this data it's going to be available before you try to get it from the service.