Sto tentando di aggiungere un singolo parametro a tutte le mie richieste Web in modo che la memorizzazione nella cache sia disabilitata forzatamente. Tutto quello che voglio fare è aggiungereRichiesta di trasformazione HTTP in Angular 2
?v=1535DC9D930 // Current timestamp in hex
fino alla fine di ogni richiesta.
Sto scrivendo questo in semplice ES5 JS, ma tutta la documentazione è in dattiloscritto che impiega un po 'di tempo a convertire. Ho il seguente finora:
(function(app) {
app.CustomHttp = ng.core
.Class({
constructor: [ng.http.Http, function(http) {
console.log(this);
this.http = http;
}],
request: function() {
return this.http.request.apply(arguments);
},
get: function() {
return this.http.get.apply(arguments);
},
post: function() {
return this.http.post.apply(arguments);
},
put: function() {
return this.http.put.apply(arguments);
},
delete: function() {
return this.http.delete.apply(arguments);
},
patch: function() {
return this.http.patch.apply(arguments);
},
head: function() {
return this.http.head.apply(arguments);
}
});
})(window.app || (window.app = {}));
(function(app) {
document.addEventListener('DOMContentLoaded', function() {
ng.core.enableProdMode();
ng.platform.browser.bootstrap(
app.AppComponent,
[ng.core.provide(ng.http.Http, { useClass: app.CustomHttp })]
).catch(function(error) {
console.error(error);
});
});
})(window.app || (window.app = {}));
L'applicazione funziona perfettamente, ma il console.log(this)
nel CustomHttp
non viene mai chiamato, e quando ho ispezionare ng.http.HTTP_PROVIDERS
nel browser non sembra essere utilizzando CustomHttp
. Ho anche provato:
[ng.http.HTTP_PROVIDERS, ng.core.provide(ng.http.Http, { useClass: app.CustomHttp })]
Nel mio boot.js
inutilmente.
Sono sicuro che c'è qualcosa di minuscolo che mi manca, o che ho massicciamente complicato questo (Quanto può essere difficile aggiungere un singolo parametro a tutte le richieste?).
http://plnkr.co/edit/6w8XA8YTkDRcPYpdB9dk?p=preview Io non capisco, ma forse questo ti aiuta https: // angolare. io/docs/js/latest/api/http/RequestOptions-class.html https://angular.io/docs/js/latest/api/http/RequestMethod-enum.html –
@AngelAngel grazie, ma ho visto quelli prima, il plunk è in dattiloscritto e la documentazione, sebbene buona, non spiega come farlo in ES5. – JosephGarrone