Access App from different controllers


#1

I’m using Ember-cli for organizing my application. I’ve extended App to have a token variable that I can access globally.

Now, I was able to access it like this: window.MyAPP.token. However, it feels a little wrong and I was wondering if there’s a different way to access token from other places.

Thanks.


#2

You can inject stuff in every route and controller with injections:

http://emberjs.com/guides/understanding-ember/dependency-injection-and-service-lookup/#toc_dependency-injection-with-code-register-inject-code

Its the what is done with the store, so its accessible everywhere


#3

I ended up having the variable in the controller and the one place different I needed to access it, I had this.controllerFor('myController').get('variable').

Thanks.