@DSA2 wrote:
Hi,
In my ionic app I want to store the application global variables which can be accessed across all the pages. For this I have created an injectable service which I import in app.module.ts file and added it into providers section.
I then inject it into home page and initialise some values in ngOnInit method. In the login page, I authenticate user and set user details into global variable. When there is successful login, I navigate to home page again using router.navigate method. The ngOnInit method of home page is called again and values are reset.
It seems when you inject a service in the constructor, a local variable is created and values set are local. Every page where I want to call it creates a new local instance. Although in constructors of each page, I declare it as public, it seems values are not getting shared across pages.
How can we achieve this? I want one public variable which can be accessible by all pages.
Regards.
Dilip
Posts: 1
Participants: 1