简体   繁体   English

在Angular中何时以及为哪个组件创建DOM?

[英]When and for which component is the DOM created in Angular?

Does each Angular component have its own DOM? 每个Angular组件都有自己的DOM吗? Or is it only one DOM for the index.html , and only the component selector inside the index.html have their template elements in the DOM? 或者它只是一个DOM的index.html ,只有内部的组件选择index.html必须在DOM的模板元素?

Here's the trick: 这是窍门:

Create an angular app, create a few components, use them in the app and Run the app: 创建一个有角度的应用程序,创建一些组件,在应用程序中使用它们并运行该应用程序:

You can check the actual DOM of the entire page by inspecting the page on your browser under Elements tab. 您可以通过在浏览器的“元素”选项卡下检查页面来检查整个页面的实际DOM。

I had already done that and the result is: 我已经做过,结果是:

Every component you're seeing on the screen is part of the actual DOM. 您在屏幕上看到的每个组件都是实际DOM的一部分。 So basically, though not sure but I am assuming based on my checks, All components are part of the index.html DOM. 所以基本上,虽然不确定,但是我根据检查来假设,所有组件都是index.html DOM的一部分。

I have tested this by viewing the ELements of the angular.io site and I found that every component displayed on the screen is part of the DOM. 我通过查看angular.io网站的ELements进行了测试 ,发现屏幕上显示的每个组件都是DOM的一部分。

暂无
暂无

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

相关问题 销毁创建的未添加到 DOM 的 HTMLElement - Destroy created HTMLElement which was not added to DOM 从Angular组件绑定到HTML模板时,iframe代码将转换为dom对象 - Iframe code is converting into a dom object when binding from Angular component to HTML template Angular 2:删除组件中的包装 DOM 元素 - Angular 2: Remove the wrapping DOM element in a component 在 Angular 中操作组件的 DOM 元素 - Manipulating a component's DOM elements in Angular 在 Angular 中,您将如何在 dom 中移动组件? - In Angular, how would you move a component in the dom? Angular 2-注入由HTML选择器创建的组件 - Angular 2 - Injecting a component created by a HTML selector Angular:如何调用动态创建组件的构造函数? - Angular: How to call constructor of dynamically created component? 当React尝试注册带有load的window.onload或window.addEventListener中运行的组件时,尚未加载DOM - DOM isn't loaded yet when React tries to registers Component which runs in window.onload or window.addEventListener with load 当元素使用 angular 中的 `renderer2.removeChild()` 从 DOM 中删除时,有没有办法取消订阅子组件的订阅? - Is there any way to unsubscribe child component's Subscriptions when element is removing from DOM using `renderer2.removeChild()` in angular? 如何将Angular Directive设置为Javascript中创建的DOM元素 - How to Set Angular Directive to the DOM element created in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM