How to access a known Ember component from console

ⅰ亾dé卋堺 提交于 2019-12-03 10:25:51

Correct me if I am wrong but it seems that you aren't using the ember inspector (available on firefox and as a bookmarklet).

Once you have that installed it is really easy to inspect debug and modify anything ember related, for the purpose of this answer I will be using the chrome version.

Open up your chrome dev tools in the tab that has your ember app running, once there head to the ember tab in the developer tools.

In order to see the components you will have to tick a checkbox

Once enabled you will be able to see all of the components currently used.

Clicking on a component will open up a panel that contains all of the component's properties.

In order to access those properties from the console all you need to do is click on the $E next to the components.

Once clicked you should see something similar in the console.

Ember Inspector ($E):  Class {helperName: (...), logout: (...), isOpenBinding: StreamBinding, currentUserBinding: StreamBinding, _morph: Morph…}

Now all you need to do in order to get the property values:

$E.get('myProperty');

And To set them:

$E.set('myProperty', newValue);

A component is just a view, so the following should work:

Ember.View.views[<GUID>]

So in your example:

Ember.View.views['ember592']

You need to use get/set if you want to modify/read the value property, for example:

Ember.View.views['ember592'].get('value')

Ember.View.views['ember592'].set('value', 'newValue')

Found a gist that works with Ember 2.13

App.__container__.lookup('-view-registry:main')[componentId]; // componentId i.e. "ember4322"

Credit goes to ngyv: https://gist.github.com/ngyv/819e2cc78eca2a3b19599707e1461205

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!