Browse Source

Refactor LogoComponent to use injectable tokens

Updated LogoComponent to use LOGO_URL_TOKEN and LOGO_APP_NAME_TOKEN for logo URL and app name, falling back to environment values if tokens are not provided. This improves flexibility and allows for easier customization of the logo and app name.
pull/23750/head
Fahri Gedik 1 year ago
parent
commit
1010923215
  1. 25
      npm/ng-packs/packages/theme-basic/src/lib/components/logo/logo.component.ts

25
npm/ng-packs/packages/theme-basic/src/lib/components/logo/logo.component.ts

@ -1,24 +1,37 @@
import { ApplicationInfo, EnvironmentService } from '@abp/ng.core';
import { EnvironmentService } from '@abp/ng.core';
import { RouterLink } from '@angular/router';
import { Component, inject } from '@angular/core';
import { LOGO_APP_NAME_TOKEN, LOGO_URL_TOKEN } from '@abp/ng.theme.shared';
@Component({
selector: 'abp-logo',
template: `
<a class="navbar-brand" routerLink="/">
@if (appInfo.logoUrl) {
<img [src]="appInfo.logoUrl" [alt]="appInfo.name" width="100%" height="auto" />
@if (logoUrl) {
<img [src]="logoUrl" [alt]="appName" width="100%" height="auto" />
} @else {
{{ appInfo.name }}
{{ appName }}
}
</a>
`,
standalone: true,
imports: [RouterLink],
})
export class LogoComponent {
private environment = inject(EnvironmentService);
get appInfo(): ApplicationInfo {
return this.environment.getEnvironment().application;
private readonly providedLogoUrl = inject(LOGO_URL_TOKEN, { optional: true });
private readonly providedAppName = inject(LOGO_APP_NAME_TOKEN, { optional: true });
get logoUrl(): string {
return (
this.providedLogoUrl ?? this.environment.getEnvironment().application?.logoUrl
);
}
get appName(): string {
return (
this.providedAppName ?? this.environment.getEnvironment().application?.name
);
}
}

Loading…
Cancel
Save