zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Angular bootstrap的一个例子

AngularBootstrap 一个 例子
2023-09-14 09:04:03 时间

A way to initialize and launch an app or system.
In Angular, an app’s root NgModule (AppModule) has a bootstrap property that identifies the app’s top-level components.

例子:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

其中bootstrap属性的值AppComponent来自文件app.component.ts:

During the bootstrap process, Angular creates and inserts these components into the index.html host web page.

index.html的内容:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>MyFirstProject</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root></app-root>
</body>
</html>

这个app-root的标签:

定义在app.component.ts的Component selector里:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":