角度5のプロジェクトでは、ビューがロードされる前にリゾルバを実行します。問題は、リゾルバから戻したいデータが観測可能なデータに依存していることです。何が表示されているビューに移動しようとしたときに、このコードでAngular execute resolve with observable
@Injectable()
export class PlayersService {
standingsSubject = new ReplaySubject<any>();
standings$ = this.standingsSubject.asObservable();
constructor(private http: HttpClient) {}
getStandings(): void {
this.http.get('http://localhost:8080/api/fixtures/standings')
.subscribe((response: any) => {
this.standingsSubject.next(response);
});
}
}
:
リゾルバ:リゾルバが使用する
@Injectable()
export class PlayersResolver implements Resolve<any> {
constructor(private playersSrv: PlayersService) {
this.playersSrv.getStandings();
}
resolve() {
return this.playersSrv.standings$;
}
}
サービスこれはコードです。どのように私のコンポーネント内のデータを取得する解決策を実装することができますか?
ありがとうございます。
これを信頼してください。あなたはサービスの中で購読したくない。 –
こんにちはJota.Toledo、どうしてですか? –