I am using Angular 2. For the global variable access, I created a service and injected it into my component pages.
I can access it in any page, but when I update that variable, the changes will not affect while accessing it in another page.
This is the code in the GlobaldataService:
import { Injectable } from '@angular/core';
@Injectable()
export class GlobaldataService {
public var1="haii";
}
This is the service that I used:
constructor(public obj: GlobaldataService){}
In one of my component pages, I updated the variable by this.obj.var1 =" hello";
In another page component alert(this.obj.var1); But it displays the older value which is "haii" how can I update the global variable .
Thanks in advance.