import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; import { ActivatedRoute, ParamMap } from '@angular/router'; import { Observable, of } from 'rxjs'; import { catchError, switchMap } from 'rxjs/operators'; import { SeoService } from 'src/app/services/seo.service'; import { LightningApiService } from '../lightning-api.service'; @Component({ selector: 'app-channel', templateUrl: './channel.component.html', styleUrls: ['./channel.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class ChannelComponent implements OnInit { channel$: Observable; error: any = null; constructor( private lightningApiService: LightningApiService, private activatedRoute: ActivatedRoute, private seoService: SeoService, ) { } ngOnInit(): void { this.channel$ = this.activatedRoute.paramMap .pipe( switchMap((params: ParamMap) => { this.error = null; this.seoService.setTitle(`Channel: ${params.get('short_id')}`); return this.lightningApiService.getChannel$(params.get('short_id')) .pipe( catchError((err) => { this.error = err; console.log(this.error); return of(null); }) ); }) ); } }