0

What are the best ways to use global variables in angular ionic? I would like to use the variable in different controllers.

1 of the variable will get the value from firebase and use in different controller. How to do this the simplest way. Thanks!

Tikboy
  • 11
  • 3

2 Answers2

1

Use $rootScope that will be accessible from multiple controllers. Ref.

OR

use

app.value('config', {
    "constant1": "value1",
    "constant2": "value2"
});

and access it

config.constant1

Do not forget to inject dependency config in controller.

my original Answer here

Regards

Community
  • 1
  • 1
Hardik Vaghani
  • 2,163
  • 24
  • 46
0

You could share variables between controllers by setting up a service: Please see: use variable of another controller angularJS with ionic

Services are the simplest form of sharing variables between controllers, you could also use 'factories' and 'providers' which are more robust in their structure and transfer.

Community
  • 1
  • 1