1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute } from '@angular/router'
3 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
4 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
5 import { RestExtractor } from '@app/shared'
6 import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
7 import { Subscription } from 'rxjs'
10 templateUrl: './video-channels.component.html',
11 styleUrls: [ './video-channels.component.scss' ]
13 export class VideoChannelsComponent implements OnInit, OnDestroy {
14 videoChannel: VideoChannel
16 private routeSub: Subscription
19 private route: ActivatedRoute,
20 private videoChannelService: VideoChannelService,
21 private restExtractor: RestExtractor
25 this.routeSub = this.route.params
27 map(params => params[ 'videoChannelId' ]),
28 distinctUntilChanged(),
29 switchMap(videoChannelId => this.videoChannelService.getVideoChannel(videoChannelId)),
30 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
32 .subscribe(videoChannel => this.videoChannel = videoChannel)
37 if (this.routeSub) this.routeSub.unsubscribe()