Angular2 - bootstrap vs method property

I am completely new to Angular2 (without the experience of previous versions). Would anyone be so kind as to explain the difference between bootstrapas a NgModuleversus property bootstrapas a method?

For example, the Angular2 Tour of Heroes tutorial app.module.tshas the following:

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule
  ],
  declarations: [
    AppComponent,
    DashboardComponent,
    HeroDetailComponent,
    HeroesComponent
  ],
  providers: [ HeroService ],
  bootstrap: [ AppComponent ]
})

In other examples, I saw things like:

let phoenixChannelsProvider = provide(PhoenixChannels, { useFactory: () => {
  return new PhoenixChannels("ws://localhost:4000/socket");
} });    
bootstrap(AppComponent, [phoenixChannelsProvider]);

If someone could even vaguely describe the difference in the application of the concept of "bootstrap" here, it would be very helpful.

+4
source share
2 answers

You need both of them:

In the first, which is a module and is basically your root module

bootstrap: [ AppComponent ] 

, , , AppComponent, .

, AppComponent, , , , , , .

, Angular :

platformBrowserDynamic().bootstrapModule(AppModule)

/ angular2.

Angular2 ? , .

Java, .

, , ( ).

, platformBrowserDynamic, - , , , ( appComponent).

, , NativeScript Angular2Universal , - (platformBrowserDynamic).

, Universal, :

platformUniversalDynamic().bootstrapModule(AppModule)

, -, :

  bootstrapWorkerApp(AppModule, []);
+4
bootstrap(AppComponent, [phoenixChannelsProvider]);

Angular2 <= RC.5

BTW: Dart Angular2 NgModule - bootstrap(...).

+3

Source: https://habr.com/ru/post/1664975/


All Articles