top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are providers in Angular 2?

0 votes
255 views
What are providers in Angular 2?
posted Dec 31, 2017 by Parampreet Kaur

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can provide services to your app by using the providers array in an NgModule.

Example

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

import { AppComponent } from './app.component';
import { UserService } from './user.service';

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

When you add a service provider to the providers array of the root module, it’s available throughout the app. Additionally, when you import a module that has providers, those providers are also available to all the classes in the app as long they have the lookup token.

Read More : https://angular.io/guide/providers

answer Apr 30, 2018 by Kuldeep Apte
...