天天看點

Angular bootstrap的一個例子

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.

例子:

Angular bootstrap的一個例子

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:

Angular bootstrap的一個例子

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的标簽:

Angular bootstrap的一個例子

定義在app.component.ts的Component selector裡:

Angular bootstrap的一個例子