gpt4 book ai didi

angular - Angular 什么时候创建组件实例

转载 作者:行者123 更新时间:2023-12-05 07:40:15 24 4
gpt4 key购买 nike

我是 Angular 的新手,从文档中我了解到我们可以通过引导 root 模块启动 Angular 应用程序,然后 Angular 可以通过创建 app component 的实例来启动应用程序并在 selector 中找到该组件的 index.html 和放置那个根组件的 View ,我的问题是 Angular 是否对所有组件使用相同的策略,例如,这是否会同时创建所有组件或创建基于在模板上声明的指令的组件。

1) i have 2 components such as app component, navbar component 2) app component have <app-navbar></app-navbar> on its template

据我了解Angular 首先创建 root component 并将该组件 View 粘贴到 root component selector(app-root) 上的 index.html 中,如果该根组件 View 有另一个名为 app-navbar 的选择器,那么它只会创建 navbar.component 的实例并将该 View 粘贴到选择器中。如果我错了请纠正我?

最佳答案

... and find the selector of this component in index.html and put the view of that root component

这只发生在定义为 bootstrap 的组件上模块装饰器中的组件。因此这里:

Angular first create root component

最好使用术语bootstrap组件,因为可以有许多 Bootstrap 组件。

i have 2 components such as app component, navbar component

Angular 编译器会生成两个工厂。在此过程中,它会遇到 <app-navbar></app-navbar>并创建适当的 View 节点。当 Angular 创建 View 时,它会为 navbar component 创建一个 View 。并实例化 NavbarComponent类。

要了解有关 View 的更多信息,请从 Here is why you will not find components inside Angular 开始

关于angular - Angular 什么时候创建组件实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46335869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com