キャッシングが強制的に無効になるように、すべてのWebリクエストに1つのパラメータを追加しようとしています。すべてのリクエストの最後に、HTTP変換リクエスト(角2)
?v=1535DC9D930 // Current timestamp in hex
を追加するだけです。
私はこれをプレーンなES5 JSで書いていますが、すべてのドキュメントはTypescriptに変換されています。私はこれまで、次のいる:
(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 = {}));
アプリは完全に動作しますが、まだCustomHttp
でconsole.log(this)
が呼ばれることは決してありません、と私は、ブラウザでng.http.HTTP_PROVIDERS
を検査するとき、それはCustomHttp
を使用するためには表示されません。私はまた試みた:
[ng.http.HTTP_PROVIDERS, ng.core.provide(ng.http.Http, { useClass: app.CustomHttp })]
私のboot.js
では無駄です。
私は行方不明の小さなものがあるか、これを大いに複雑にしていると確信しています(すべての要求に単一のパラメータを追加するのはどれほど難しいでしょうか?)。
http://plnkr.co/edit/6w8XA8YTkDRcPYpdB9dk?p=previewを私はかなり理解していないが、多分これはあなたがHTTPSに役立ちます://角度。 io/docs/js/latest/api/http/RequestOptions-class.html https://angular.io/docs/js/latest/api/http/RequestMethod-enum.html –
@AngelAngelありがとうございます以前は、plunkがtypescriptになっていて、ドキュメンテーションは良いですが、ES5でそれを行う方法を説明していません。 – JosephGarrone