import { Component, OnInit, ChangeDetectionStrategy, Input, ChangeDetectorRef, OnDestroy } from '@angular/core'; import { Observable, Subscription } from 'rxjs'; import { StateService } from '../services/state.service'; @Component({ selector: 'app-fiat', templateUrl: './fiat.component.html', styleUrls: ['./fiat.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class FiatComponent implements OnInit, OnDestroy { conversions$: Observable; currencySubscription: Subscription; currency: string; @Input() value: number; @Input() digitsInfo = '1.2-2'; constructor( private stateService: StateService, private cd: ChangeDetectorRef, ) { this.currencySubscription = this.stateService.fiatCurrency$.subscribe((fiat) => { this.currency = fiat; this.cd.markForCheck(); }); } ngOnInit(): void { this.conversions$ = this.stateService.conversions$.asObservable(); } ngOnDestroy(): void { this.currencySubscription.unsubscribe(); } }