How to maintain global variable?

Please help me to handle global variables :frowning.
I have developing App using rest API. My problem is when user login I have to store the API token into storage from server but my problem when I retrieve the token some time its return null value
here I share my code for reference how to handle the global variable that can retrieve from the server


      .subscribe((data) =>{
        console.log('login processing....');


public api_token:string;

async getToken(){
            this.api_token = data;

Read the Angular docs on providers. Use a provider to talk to your API, and have your pages talk to your provider.

1 Like