angular4 - create a global variable that can be also accessed in views

Discussão em 'Angular' iniciado por user1985273, Janeiro 23, 2025.

  1. user1985273

    user1985273 Guest

    Is it possible to create a global variable that can be accessed from both components and views?

    At the moment i created a global.ts file like this:

    export const GlobalVariable = Object.freeze({
    BASE_API_URL: 'http://www.asdf.com/'
    });


    And then i have to import it in every component:

    import { GlobalVariable } from '../shared/global';


    Then i can use "GlobalVariable.BASE_API_URL" in those components. There are two problems with it i dont like. First the part that i have to import it in every single component, is it possible to do a import for all components once? But actually thats a problem i can live with. The bigger problem is that i can seem to access that variable in my html files. Is there a solution for this?

    Continue reading...

Compartilhe esta Página