diff --git a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts index afdda6849b3..f41c5c9426f 100644 --- a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts @@ -25,11 +25,18 @@ export class LocalizationService { /** * Returns currently selected language + * Even though this looks like it's redundant to return the same value as `getLanguage()`, + * it's actually not. This could be invoked any time, and the latestLang could be different from the + * sessionState.getLanguage() value. */ get currentLang(): string { return this.latestLang || this.sessionState.getLanguage(); } + get currentLang$(): Observable { + return this.sessionState.getLanguage$(); + } + get languageChange$(): Observable { return this._languageChange$.asObservable(); } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/handlers/document-dir.handler.ts b/npm/ng-packs/packages/theme-shared/src/lib/handlers/document-dir.handler.ts index fb5d65710f6..8260a39c270 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/handlers/document-dir.handler.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/handlers/document-dir.handler.ts @@ -1,7 +1,7 @@ import { getLocaleDirection, LocalizationService } from '@abp/ng.core'; import { Injectable, Injector } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; -import { map, startWith } from 'rxjs/operators'; +import { map } from 'rxjs/operators'; import { LocaleDirection } from '../models/common'; @Injectable() @@ -14,17 +14,11 @@ export class DocumentDirHandlerService { private listenToLanguageChanges() { const l10n = this.injector.get(LocalizationService); - // will always listen, no need to unsubscribe - l10n.languageChange$ - .pipe( - startWith(l10n.currentLang), - map(locale => getLocaleDirection(locale)), - ) - .subscribe(dir => { - this.dir.next(dir); - this.setBodyDir(dir); - }); + l10n.currentLang$.pipe(map(locale => getLocaleDirection(locale))).subscribe(dir => { + this.dir.next(dir); + this.setBodyDir(dir); + }); } private setBodyDir(dir: LocaleDirection) {