export class EpisodeComponent {


    public episodes: number[] = [];
    public episodeData?: Episode | null;
    public charactersData?: Character[] | null = [];

    constructor(private _service: RmserviceService) {
        for (let i = 0; i < 51; i++) {
            this.episodes.push(i + 1);
        }
    }

    getDataFromEpisode(q: number): void {
        let charsTemp: number[];
        this._service.getEpisodeData(q)
            .pipe(
                switchMap(episode => {
                    this.episodeData = episode;
                    charsTemp = this._service.extractIdsFromLinks(episode!.characters);
                    return this._service.getCharactersData(charsTemp);
                })
            )
            .subscribe(cd => {
                this.charactersData = cd;
            });
    }
}

By davs