Global Var


#1

How I can create a Global variable or Global class?, with injectable service?


How to Access Data/Variable from One Page to Another
#2

Try this:

// global_service.ts
import {Injectable} from 'angular2/core';  
import {Http, Headers} from 'angular2/http';

@Injectable()
export class GlobalService {  
    constructor(private http: Http) {
    }
}
// app.ts
@App({
  providers: [GlobalService], // constructed once
  config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
class MyApp {...}
// page.ts
@Page({
})
export class SpecialsPage {
  // shared instance being injected
  constructor(private global: GlobalService) {
  }
}

#3

Link to formatted code.


#4

global class

export class Global {
  public static globalVar1: string = 'lol.com';
  public static globalVar2: number = 42;
}

global variables

export const globalVar1: string = 'lol.com';
export const globalVar2: number = 42;

PS. It’s not service, and it’s not injectable.
PPS. TS


#5

Mmmmm, it’s easier if you tell us what you want to do. Maybe this will help you http://www.gajotres.net/ionic-2-sharing-data-between-pagescomponents/