How to access the global object in ember-cli app

In a normal emberjs app, you can do

App.__container__.lookup("controller:application")

      

How can I achieve this latest version of ember-cli? I dont see any global app object to reference.

+3


source to share


3 answers


Say you built your application like this:

ember new kittens

      



Your debug statement will look like this:

Kittens.__container__.lookup("component:bootstrap-datepicker")

      

+4


source


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/

0


source


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.

enter image description here

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.

0


source







All Articles