Home > Net >  How to create Global variable in Angular for multiple Components
How to create Global variable in Angular for multiple Components

Time:12-01

I wanted to create a global variable which is of type boolean, I wanted to utilize the same variable in multiple components (Without using Service).To be precise I also wanted to capture the variable value from any component if it is changed in other components.

CodePudding user response:

try declaring the variable in environment.ts file

CodePudding user response:

There are few options to do it.

  1. Environment variables : Declare the variable in environment.ts. Do note that you need to replicate it across envionment.prod.ts and other environment files if you may have.
  2. Injection Token : Create a custom injection token, and pass it as a provider in your Component or Module. Details
  • Related