How do I access the directive instance in angular from console?

喜你入骨 提交于 2019-11-29 11:15:17

Directive instance doesn't differ from other providers in this respect, it can be retrieved from injector.

In order to retrieve provider instance, it is necessary to have provider token, which is directive class. Since application classes aren't exposed to global scope, debug element providerTokens can be inspected.

Given the application is unminified and functions preserve their original names, directive (provider) token is retrieved like:

var FooDirective = ng.probe($0).providerTokens.find(token => token.name === 'FooDirective');

And directive (provider) instance is retrieved like:

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