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!
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!
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
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.