クライアント側のタイマーを定期的に設定してサーバーに自動的にリクエストする方法はありますか?あなたはngOnInit内のJavascriptののsetInterval関数を使用することができHTTPリクエストのタイマー設定
例えばPolling(){
this.http.makeRequestEvery1min(){
subscribe(data => {
)
}
//request should be every sent every 1 minute
}
クライアント側のタイマーを定期的に設定してサーバーに自動的にリクエストする方法はありますか?あなたはngOnInit内のJavascriptののsetInterval関数を使用することができHTTPリクエストのタイマー設定
例えばPolling(){
this.http.makeRequestEvery1min(){
subscribe(data => {
)
}
//request should be every sent every 1 minute
}
Rx.Observable.interval(60*1000).
switchMap(x=> http.getSomething())
.subscribe(x=>console.log(x))
。
のsetInterval(関数(){// が何かをする}、3000)
あなたはインターバル機能を使用する必要があります。
.controller
('sampleController',['$scope','$interval', function ($scope, $interval) {
function Polling(){
//Write your http request here.
}
var interval = 1000; //in milliseconds
var intervalPromise = $interval(polling, 1000);
//To Kill the interval function on page closure or route change
$scope.$on('$destroy', function() {
if (angular.isDefined(intervalPromise)) {
$interval.cancel(intervalPromise);
}
});
}]);
例えば、このstackoverflowの投稿を見てください。 http://stackoverflow.com/questions/35316583/angular2-http-at-an-interval – Kalyan
これは最も簡単な方法です。 – Thibs