variable global en angular code example
Example: how to make global variable in angular
Here is the simplest solution w/o Service nor Observer:
Put the global variables in a file an export them.
'use strict';
export const sep='/';
export const version: string="22.2.2";
To use globals in another file use an import statement: import * as myGlobals from 'globals';
Example:
import {Component, OnInit} from 'angular2/core';
import {Router} from 'angular2/router';
import {HeroService} from './hero.service';
import {HeroDetailComponent} from './hero-detail.component';
import {Hero} from './hero';
import * as myGlobals from 'globals';
export class HeroesComponent implements OnInit {
public heroes: Hero[];
public selectedHero: Hero;
public helloString: string="hello " + myGlobals.sep + " there";
...
}
}
Thanks @eric-martinez