Hi Francisc, I think that you need is $cacheFactory, if you look at the doc <https://docs.angularjs.org/api/ng/service/$http>, you will see that $http use caching when enabled.
You can provide you own class of caching, but it has to provide the same methods than $cacheFactory (see the do <https://docs.angularjs.org/api/ng/service/$cacheFactory>c). Then, once you cache system implemented, put in your module .config() : $httpProvider.defaults.cache <https://docs.angularjs.org/api/ng/service/$http#properties_defaults> = myCacheService; <https://docs.angularjs.org/api/ng/service/$http#properties_defaults> So every time that $http make a request, it will call your cache service. You see ? Regards, Charly. On Thursday, 10 July 2014 14:18:24 UTC+2, Francisc wrote: > > Hello, > > I would like to be able to intercept all AJAX calls made with $http > service to prevent the any XHR calls and respond with data from an Angular > service (for example). > So the data is in memory, not from a remote resource. > > I want to be able to to this at runtime at the switch of a button, e.g. > "Cut server communication ON / OFF". > > As far as I can see, HTTP request interceptors can only modify the config > object and return it, but cannot return actual data as response. > > How can this be achieved? > > Thank you. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
