Bhushan Gadekar Bhushan Gadekar - 2 months ago 39
TypeScript Question

alternative for provide in angular2?

I had used

provide
from @angular/core.

for eg.

import {provide} from '@angular/core';
import {ToastOptions} from "ng2-toastr/ng2-toastr";
let options = {
positionClass: 'toast-bottom-right',
};

//then used inside providers array as :
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
providers: [
appRoutingProviders,
ConfigService,
ToastsManager,
provide(ToastOptions, { useValue: new ToastOptions(options)})
],
bootstrap: [AppComponent]
})
export class AppModule { }


but I cant find how to do this in angular 2 final?

any inputs?

Answer

Syntax has changed a bit since RC6, this is how it should be now:

{ provide: ToastOptions, useValue: new ToastOptions(options) }

You can also delete import {provide} from '@angular/core';, you don't need it anymore.

Comments