如何从控制台访问angular中的指令实例? [英] How do I access the directive instance in angular from console?

查看:160
本文介绍了如何从控制台访问angular中的指令实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng.probe($0).componentInstance-将引用实例.

是否可以从控制台访问指令实例?

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

推荐答案

在这方面,指令实例与其他提供程序没有区别,可以从注入器中检索它.

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

为了检索提供程序实例,必须具有提供程序令牌,它是指令类.由于应用程序类未在全局范围内公开,因此可以检查调试元素providerTokens.

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);

这篇关于如何从控制台访问angular中的指令实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆