How to use InjectionToken with the inject function in Angular

Discussão em 'Angular' iniciado por Raphaël Balet, Março 22, 2025.

  1. I have the following

    export const BASE_URL = new InjectionToken<string>('my.base.url')


    I'd like to be using it inside my component.
    For now I'm doing the following inside the constructor, but I would like to use the inject function like follow

    baseUrl = inject(BASE_URL) // Wished

    constructor(@Inject(BASE_URL) baseUrl: string {} // Now


    Sadly this isn't working and couldn't figure it out how to handle it properly.
    Can someone please help me with that ?

    Continue reading...

Compartilhe esta Página