1//Use a shared service:
2import { Injectable } from '@angular/core';
3
4@Injectable()
5export class AppService{
6 myGlobalVar;
7
8 constructor(){
9 this.myGlobalVar = true;
10 alert("My intial global variable value is: " + this.myGlobalVar);
11 }
12
13 setMyGV(val: boolean){
14 this.myGlobalVar = val;
15 }
16
17 getMyGV(val: boolean){
18 return this.myGlobalVar;
19 }
20}
21//Remember to add it to the app.module providers