how to make global variable in angular

Solutions on MaxInterview for how to make global variable in angular by the best coders in the world

showing results for - "how to make global variable in angular"
Victoria
28 Aug 2019
1Here is the simplest solution w/o Service nor Observer:
2
3Put the global variables in a file an export them.
4
5//
6// ===== File globals.ts    
7//
8'use strict';
9
10export const sep='/';
11export const version: string="22.2.2";    
12To use globals in another file use an import statement: import * as myGlobals from 'globals';
13
14Example:
15
16// 
17// ===== File heroes.component.ts    
18//
19import {Component, OnInit} from 'angular2/core';
20import {Router} from 'angular2/router';
21import {HeroService} from './hero.service';
22import {HeroDetailComponent} from './hero-detail.component';
23import {Hero} from './hero';
24import * as myGlobals from 'globals'; //<==== this one (**Updated**)
25
26export class HeroesComponent implements OnInit {
27    public heroes: Hero[];
28    public selectedHero: Hero;
29    // 
30    //
31    // Here we access the global var reference.
32    //  
33    public helloString: string="hello " + myGlobals.sep + " there";
34
35         ...
36
37        }
38    }
39Thanks @eric-martinez
queries leading to this page
how to create global variable in angularcall global variable in angular jsangular 10 global variabledeclare globals angularangular access a global variableglobal variable angular 9variables globales angularhandle global variables in angular universal how to set up global variables in angularhow to define global variable in react js like angularhow to change value of global variable in angularset a global variable in angular jscan you make a global variable in angularangular global variable 5cglobal function in angular 8set global variable in angularangular export global variablehow to use a global variable in angularhow to make global variable in angulardynamic global variable in angular 7global variable in angular without importdeclare global variable in angular componentare there any global reference variables in angularhow to use declare variable use like global in whole project in angular 8angular get global variablehow to use a global window variable in angularset a global variable angularangularjs set global variableshow to make global variables an enviroment varibalble angularangular set global variableglobal script in angularcreate global variable in angular componentglobal variable angular htmldefine global variable angularglobal variable in angular 11 componenthow to set global variable in angularjsangular can global variable access in browserhow to declare global variable in angular 8angular 11 declare global variableset global variable angularglobal var angularhow to declare global variable in angularjsglobal variables in angular 10how to make global varibale in angualrreference global variable in angularhow to use global function in angular jsangular using global js variablehow to create global variable in angularjsangular how to set a global variable to access it from all the appangular make globalsangular global variableshow to make global varibale in angualr 10angular keep global variablecan i make global variable angularangular use variable globalglobal variable angularhow to make variable global in angularangular access global variableuse global variable component angularhow to define global variable in angularglobal var angular 10global variable in angularcreate global function and use in html angularglobal variables angular 8how to use a global variable in html angularangular declare variable globalyangular 11 global variablehow to declare global variable in angularuse global variable in angular templatehow to make global function in angularhandle global variables in angular universal with 22angular 10 22global variuable in angularglobal variables in anguarhow to declare global variable in angular 11angular define global variablehow to asian the global variable in angular 10global html variable angukarhow to make declare a variable as global in angularhow to access global variable in angular jsdeclare var global nodejs global angularangular 8 how to create global functionvariable global en angularlocal and global variables in angularangular create a global function set value as global in angular 8angular variable globalcreate a global access variable in angularangular use globale javascript variablecan you make a global varible in angularhandle global variables in angular universal with 27angular 10 27how to make a global variable in angularhandle global variables with angular 10 universal set a global variable angular componentdisplay global variable angular on htmluse global variable in in 2 component angularangular global variable for all componentshow to declare global variable use hole project in angular 8global variable angular 10angular global variable filehandle global variables in angular universal with angular 10 how to make a global varible inside a angular functionangular how to set a global variableglobal variables in html angular 8angularjs global variableangular 11 set global variablesvariable global angularangular declare global variableglobal value in html angularcreate global variable in angular 11set global variables in angular universalangular create global variableglobal variable for application angularhow to have a global variable in all your angular filescreate global variable file in angular with clihow to have global variables in angularangular 5 global variablesglobal variable declaration in angular 10declare global variable in angularhandle global variables in angular universal with 22angular 9 22global variables in angularcreate a global variable in angular and accessglobal in angularangular global variableglobal function in angualr 10variables globales en angularhow to make a variable global in angular 8how to declare global variable and send to any component in angular 8how to defince global variable in angularhow to change a global variable value in a function angular 8how to set global variable in anguar and access in another componenthow angular handle global variableshow can create a global function in angular jsangular1 global variableangular 11 update a global variableangular global variable in htmlangular global js variableangular 2 global variableglobal variable in angularjsangular declare globalglobal variable in angular 8angular save global variablehandle global variables in angularhow to assign a global variable in angular that reflects change in every componentset a global object in angularglobal variable declaration in angular 8global functions in angularhow to have a variable be a global variable in angularglobal function in angualrangular variables globalesglobal variable in angular 10use a global variable in angular componentangular 12 global variableglobal variable angularjshow to use declare var in angular use in global variable whole projectvariable globale angularhow to make global variable in angular