Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 264
Vinay K Avatar asked Feb 08 '18 12:02

Vinay K


1 Answers

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);
like image 141
Estus Flask Avatar answered Sep 19 '22 05:09

Estus Flask