Tikboy
Tikboy

Reputation: 11

Global Value Ionic Angular

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!

Upvotes: 0

Views: 181

Answers (2)

Hardik Vaghani
Hardik Vaghani

Reputation: 2173

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

Upvotes: 1

user2672124
user2672124

Reputation:

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.

Upvotes: 0

Related Questions