我想每隔1秒發一次請求,但超時不起作用。Angular 4 - 超時請求
matchlist.service.ts
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/timeout';
getMatch(matchId: number): Promise<Match[]> {
let matchUrl: string = 'https://br1.api.riotgames.com/lol/match/v3/matches/'+ matchId +'?api_key=';
return this.http.get(matchUrl)
.timeout(1000)
.toPromise()
.then(response => response.json().participants as Match[]);
};
matchlist.component.ts
self.matchlist.forEach(function(matches){
self.MatchlistService.getMatch(matches.matchId)
.then((match: Match[]) => {
self.match = match;
return self.match;
}).catch(
err => console.log(err)
);
});
你有什麼錯誤嗎? – Aravind
沒有錯誤,只有forEach一次執行所有請求 –