Created
January 9, 2020 12:49
-
-
Save FFKL/cfd3c6b551f4c04f2bdff6f11a1e42ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core'; | |
import { TranslateService } from '@ngx-translate/core'; | |
import { get } from 'lodash'; | |
import { Subscription } from 'rxjs'; | |
import { ToursCatalog } from 'package-types'; | |
@Pipe({ | |
name: 'departureCityLabel', | |
pure: false | |
}) | |
export class DepartureCityLabelPipe implements PipeTransform, OnDestroy { | |
private onLangChange: Subscription; | |
constructor(private translateService: TranslateService, private cd: ChangeDetectorRef) {} | |
transform(value: ToursCatalog.DepartureSelector): string { | |
if (!this.onLangChange) { | |
this.onLangChange = this.translateService.onLangChange.subscribe(() => this.cd.markForCheck()); | |
} | |
return get(value, `text.${this.translateService.currentLang}`); | |
} | |
ngOnDestroy(): void { | |
if (this.onLangChange) { | |
this.onLangChange.unsubscribe(); | |
this.onLangChange = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment