각도 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, 왜 안 되니? –