ember.js - Ember-CLI - How to access application classes -
previously when developed ember application used app global object , every class stored in big object.
like this
window.app.mymodel = em.object.extend({}); and in browser console, able do
app.mymodel.create(); so easy me access mymodel class.
now started experiments ember-cli, don't have experience kind of tools. followed documentations , created model service this.
var service = ember.object.extend({}); export default service but now, how access service class browser console? way found was:
app.__container__.resolve('model:service') but don't much. there better way? btw, can please explain how export works? or there source (documentation, article) can study it?
thanks lot response.
if you're aiming have available in places throughout application you'll typically want register on container.
there multiple ways access container, , you're correct in 1 found less ideal. running joke "any time directly access __container__ need add more underscores."
to directly control how things registered on container , injected container typically want use initializer. using initializers in ember-cli super-easy, they're executed automatically.
checking out documentation can see access application's container argument allows manipulate in safe manner.
once have access container can use register , inject make content available in particular locations. introduced here. 1 note, accessing things inside of container outside context of app (browser console) require usage of app.__container__ , expected use pattern.
and export you're running es6 module system construct, it's not ember-specific. playing es6 module transpiler can give sense of goes in , comes out in "we can today" type of javascript.
Comments
Post a Comment