简体   繁体   English

Angular如何检查哪个组件是div

[英]Angular how to check from which component is a div

I'm interested in how to check in console which component was rendered.我对如何在控制台中检查渲染了哪个组件感兴趣。 I mean, let's assume that in console -> Elements you can see a lot of divs, for example.我的意思是,让我们假设在控制台 -> 元素中,例如,您可以看到很多 div。 How can you check from which component are this divs coming?你如何检查这个 div 来自哪个组件?

@Component({
    selector: 'my-component',
    template: '<div><div></div></div>'
})
export class MyComponent {
...
}

If you add the component above in your app, you should be able to see <my-component>...</my-component> in your DevTools > Elements panel.如果您在应用程序中添加上述组件,您应该能够在 DevTools > Elements 面板中看到<my-component>...</my-component>

You can also use the Angular DevTools extension to explore the HTML of your components.您还可以使用Angular DevTools 扩展来探索您的组件的 HTML。

You can simply inspect the HTML in Chromes' Dev Tools.您可以在 Chrome 的开发工具中简单地检查HTML Simply by right-clicking and selecting inspect .只需右键单击并选择inspect In the Elements section where all of the page's HTML is shown you can see different <div> etc. If you observe it closely there are also tags of components that are used by angular to display those <div> .在显示所有页面HTMLElements部分中,您可以看到不同的<div>等。如果仔细观察,还有 angular 使用的组件标签来显示这些<div>

For example, in the simple stackblitz Angular project.例如,在简单的 stackblitz Angular 项目中。 Simple inspection of the HTML will show us this HTML 的简单检查将向我们展示这一点

检查的示例图像

Here you can see that <h1> is inside the hello-component of Angular which is shown by <hello.... > tag.在这里您可以看到<h1>在 Angular 的hello-component内,由<hello.... >标签显示。 Which is inside another component my-app-component called <my-app...> .它位于另一个名为my-app-component <my-app...> By this logic, you can easily see which HTML is inside which Angular Component通过这个逻辑,你可以很容易地看出哪个HTML在哪个 Angular 组件里面

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM