Back to overview

Angular baseHref

Angular
import {APP_BASE_HREF, PlatformLocation, registerLocaleData} from '@angular/common';

export function getBaseHref(platformLocation: PlatformLocation): string {
  return platformLocation.getBaseHrefFromDOM();
}

@NgModule({
  providers: [
    {
      provide: APP_BASE_HREF,
      useFactory: getBaseHref,
      deps: [PlatformLocation],
    },
  ],
})
export class AppModule {}
export class ConsumeComponent {
  constructor(@Inject(APP_BASE_HREF) baseHref: string) {}
}