I have a service holding all my API endpoint connectors. Those endpoint connectors are ngResource objects.
In some of them I override default methods, such as get
or query
for example to add responseTransformers
. I'd like to be able to set timeout
property of get
method to stop one request before sending another, but I want to do it not in my service, where I define all $resource
s:
this.collections = $resource(BackendConfig.apiUrl + 'collections/:uid/', {}, {
query: {
isArray: false,
method: 'GET',
timeout: myTimeoutPromise
},
});
but on runtime, just before I do this
Resource.collections.query().then(function () {});
Analysing code I came into conclusion, that it is possible to override params (2nd parameter), but not actions (3rd).
I found possible (not yet implemented) solution: create new service holding all timeouts (let's say Interrupter), inject it with my Resource service where I need it and define timeout promises there. Is there more convenient solution?