How to access the global object in ember-cli app
In the Ember CLI, when defining an initializer, you can do something like:
ember generate initializer my-cool-init
And in the file: app/initializers/my-cool-init.js
there is something like:
export default {
name: 'my-cool-init',
initialize: function initialize(container/*, application*/) {
var foobar = container.lookup('controller:application');
// inject or preload stuff etc
}
};
http://emberjs.com/api/classes/Ember.Application.html#toc_initializers
http://emberjs.com/guides/understanding-ember/dependency-injection-and-service-lookup/
source to share
2 options
- Ember Inspector Chrome Extension
- Use
ember-export-application-global
addon to open the application as a global variable
Ember Inspector Chrome Extension
Check out the Ember Inspector on the Chrome Web Store . This is a Chrome extension that provides debugging and validation tools for your Ember app.
You can visually access the container, the current view hierarchy, a list of the contents of the Ember-Data store, and more.
For example, if you open the inspector on discuss.emberjs.com, you will see that there are 11 controllers, and you can check each one to see their attributes. You can even send objects to the console so you can play with them programmatically.
Use ember-export-application-global
Another way is to use the ember-export-application-global ember-cli hadronic package. This package sets up a global variable containing a reference to your application. This allows you to access the container in the way you originally mentioned.
source to share