Bootstrapping Providers

The bootstrap process also starts the dependency injection system in Angular.We won't go over Angular's dependency injection system here - that is covered later.Instead let's take a look at an example of how to bootstrap your application with application-wide providers.

For this, we will register a service called GreeterService with the providers property of the module we are using to bootstrap the application.

app/app.module.ts

  1. import { BrowserModule } from '@angular/platform-browser';
  2. import { NgModule } '@angular/core';
  3. import { AppComponent } from './app.component'
  4. import { GreeterService } from './greeter.service';
  5. @NgModule({
  6. imports: [BrowserModule],
  7. providers: [GreeterService],
  8. declarations: [AppComponent],
  9. bootstrap: [AppComponent]
  10. })
  11. export class AppModule { }

View Example

原文: https://angular-2-training-book.rangle.io/handout/bootstrapping/bootstrapping_providers.html