mirror of https://github.com/abpframework/abp.git
1 changed files with 35 additions and 31 deletions
@ -1,40 +1,44 @@ |
|||
import { Injectable, effect, inject } from "@angular/core"; |
|||
import { Title } from "@angular/platform-browser"; |
|||
import { TitleStrategy, RouterStateSnapshot } from "@angular/router"; |
|||
import { ConfigStateService } from "./config-state.service"; |
|||
import { LocalizationService } from "./localization.service"; |
|||
import { toSignal } from "@angular/core/rxjs-interop"; |
|||
import { Injectable, effect, inject } from '@angular/core'; |
|||
import { toSignal } from '@angular/core/rxjs-interop'; |
|||
import { TitleStrategy, RouterStateSnapshot } from '@angular/router'; |
|||
import { Title } from '@angular/platform-browser'; |
|||
import { ConfigStateService } from './config-state.service'; |
|||
import { LocalizationService } from './localization.service'; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root' |
|||
providedIn: 'root', |
|||
}) |
|||
export class AbpTitleStrategy extends TitleStrategy { |
|||
protected readonly title = inject(Title); |
|||
protected readonly configState = inject(ConfigStateService); |
|||
protected readonly localizationService = inject(LocalizationService); |
|||
routerState: RouterStateSnapshot; |
|||
projectName = toSignal(this.configState.getDeep$("localization.defaultResourceName"), { initialValue: "MyProjectName" }); |
|||
langugageChange = toSignal(this.localizationService.languageChange$); |
|||
protected readonly title = inject(Title); |
|||
protected readonly configState = inject(ConfigStateService); |
|||
protected readonly localizationService = inject(LocalizationService); |
|||
protected routerState: RouterStateSnapshot; |
|||
|
|||
override updateTitle(routerState: RouterStateSnapshot) { |
|||
let title = this.buildTitle(routerState); |
|||
this.routerState = routerState; |
|||
projectName = toSignal(this.configState.getDeep$('localization.defaultResourceName'), { |
|||
initialValue: 'MyProjectName', |
|||
}); |
|||
langugageChange = toSignal(this.localizationService.languageChange$); |
|||
|
|||
if (title === undefined) { |
|||
this.title.setTitle(`${this.projectName()}`); |
|||
return; |
|||
} |
|||
constructor() { |
|||
super(); |
|||
effect(() => { |
|||
if (this.langugageChange()) { |
|||
this.updateTitle(this.routerState); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
const localizedTitle = this.localizationService.instant({ key: title, defaultValue: title }); |
|||
this.title.setTitle(`${localizedTitle} | ${this.projectName()}`); |
|||
} |
|||
override updateTitle(routerState: RouterStateSnapshot) { |
|||
let title = this.buildTitle(routerState); |
|||
|
|||
constructor() { |
|||
super(); |
|||
effect(() => { |
|||
if (this.langugageChange()) { |
|||
this.updateTitle(this.routerState); |
|||
} |
|||
}); |
|||
if (!title) { |
|||
this.title.setTitle(this.projectName()); |
|||
return; |
|||
} |
|||
} |
|||
|
|||
this.routerState = routerState; |
|||
|
|||
const localizedTitle = this.localizationService.instant({ key: title, defaultValue: title }); |
|||
this.title.setTitle(`${localizedTitle} | ${this.projectName()}`); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue