5

ng.probe($0).componentInstance -- will give the reference to the instance.

Is there any way to access the directive instance from the console?

1 Answer 1

6

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);
Sign up to request clarification or add additional context in comments.

1 Comment

very impressive!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.