简体   繁体   English

Chrome 开发工具可以帮助找出 Angular 组件名称吗?

[英]Can Chrome Dev tools help figure out Angular component name?

Assuming that I have the Angular source code for the application, how can I use Chrome Developer tools to figure out the name of a specific Angular component?假设我有应用程序的 Angular 源代码,我如何使用 Chrome Developer 工具找出特定 Angular 组件的名称?

For example, let's say the application makes use of a popup dialog box and I want to find the source code for the dialog box.例如,假设应用程序使用了一个弹出对话框,我想找到该对话框的源代码。 Can Chrome Developer tools help me figure out then name of the component? Chrome 开发人员工具可以帮助我找出组件的名称吗?

So far I have been drilling down the elements tree in Chrome Dev tools and when I think I have the element for the dialog box I search the angular code for the HTML.到目前为止,我一直在 Chrome Dev 工具中钻取元素树,当我认为我有对话框的元素时,我搜索 HTML 的角度代码。 However, I often get false matches and it is time consuming.但是,我经常得到错误的匹配,而且很耗时。 I was wondering if there was a better way I might not be familiar with.我想知道是否有更好的方法我可能不熟悉。

Use Augury:使用占卜:

You can use Augury .您可以使用占卜 It's a Chrome and Firefox Extension Managed by the folks at Rangle .它是由Rangle 人员管理的 Chrome 和 Firefox 扩展。

Once you've installed it, just open Chrome Dev Tools(assuming you're using Chrome), and it will be visible as one of the Tabs in the tools.安装后,只需打开 Chrome Dev Tools(假设您使用的是 Chrome),它将作为工具中的选项卡之一可见。

You can simply select a Component from the Web page and it is going to accurately mark the Component that you were on as of then.您只需从网页中选择一个组件,它就会准确地标记您当时所在的组件。

在此处输入图片说明

Use ng.probe($0).componentInstance使用ng.probe($0).componentInstance

You can select a component using the Element Selector from the Elements Tab.您可以使用“元素”选项卡中的“元素选择器”来选择一个组件。 And then go to the Console Tab, and type in:然后转到控制台选项卡,并输入:

ng.probe($0).componentInstance

This is going to give you the Component Instance of the recently selected Component along with its name and then you can look for it accordingly.这将为您提供最近选择的组件的组件实例及其名称,然后您可以相应地查找它。 Something like this:像这样的东西:

在此处输入图片说明

NOTE: There methods would only work in DEV mode.注意:这些方法只能在 DEV 模式下工作。

It seems that ng.probe($0).componentInstance doesn't work any more with Ivy.似乎ng.probe($0).componentInstance不再适用于 Ivy。 What worked with me though is ng.getOwningComponent($0) .不过对我ng.getOwningComponent($0)ng.getOwningComponent($0)

  • Inspect an element inside the looked-for component.检查查找的组件内的元素。
  • While element is still selected, type ng.getOwningComponent($0) in the console.当元素仍处于选中状态时,在控制台中键入ng.getOwningComponent($0)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Chrome开发工具中调试导入的Angular库 - Debugging imported Angular library in chrome dev tools 如何在 chrome 开发工具中使用监视表达式来监视角度组件中的变量(“this”对象的属性)? - How to use watch expressions in chrome dev tools to watch variables in an angular component (properties of 'this' object)? 如何在Chrome开发工具中获取地图角度CLI css文件? - How to Source Map Angular CLI css files in Chrome Dev Tools? 我不明白为什么 Angular 组件 class 添加实现 onInit 接口 - I can't figure out why Angular component class add implements onInit interface 角材料配置错误和警告,请帮我弄清楚 - Angular material Configuration Error and Warning Please Help me to figure out Angular Chrome Dev Tools 扩展错误:“Angular DevTools 仅支持开发构建。” - Angular Chrome Dev Tools extension error: "Angular DevTools only supports development builds." 试图弄清楚如何将组织映射到角组件中的基础 - Trying to figure out how to switchMap an Organization to a Base in an Angular Component 找出在 Karma 测试期间哪个 Angular 组件发出错误 - Figure out which Angular component issues the error during Karma test Angular 5 Http api请求在chrome dev工具中得到响应,但不会返回 - Angular 5 Http api request gets response in chrome dev tools but won't return Angular CLI 的“ng serve”在 chrome 开发工具中出现错误时不引用打字稿源 - Angular CLI's "ng serve" doesn't refer to typescript sources upon errors in chrome dev tools
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM