Ask Your Question
4

How can I set the base href through ng serve in Angular 15?

asked 2023-05-04 12:30:17 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-04 12:49:02 +0000

woof gravatar image

Angular 15 does not exist. The latest version of Angular as of May 2021 is version 12. However, to set the base href in Angular, you can add it to the index.html file like so:

<base href="/your-base-href/">

Or, you can use the APP_BASE_HREF provider in your app module to specify the base href programmatically.

In your app.module.ts, import the APP_BASE_HREF token and set its value to your desired base href:

import { NgModule } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';

@NgModule({
  providers: [
    { provide: APP_BASE_HREF, useValue: '/your-base-href/' }
  ]
})
export class AppModule { }

This will set the base href for your entire Angular application. Note that when using ng serve, any changes made to index.html will be hot-reloaded, but changes to app.module.ts will require a server restart.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-04 12:30:17 +0000

Seen: 17 times

Last updated: May 04 '23