Reputation: 1789
I am trying to use provide in bootsrap but not working, here is my code:
import { NgModule, provide } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import {AboutComponent} from './about/about.component';
import {LoginComponent} from './account/login/login.component';
import { FormsModule } from '@angular/forms';
import { HttpModule,BaseRequestOptions } from '@angular/http';
import { AuthenticationService} from './account/login/login.service';
import appRoutes from './app.router';
/**
* Extending BaseRequestOptions to inject common headers to all requests.
*/
class CustomRequestOptions extends BaseRequestOptions {
constructor() {
super();
this.headers.append('Authorization', 'my-token');
this.headers.append('foo', 'bar');
}
}
@NgModule({
imports: [BrowserModule, appRoutes, FormsModule,
HttpModule],
declarations: [AppComponent, HomeComponent, AboutComponent, LoginComponent],
bootstrap: [AppComponent,
provide({useClass: CustomRequestOptions}) ],
providers: [
AuthenticationService
]
})
export class AppModule { }
I am geting error provide not defined. Anyone know what is problem and how to solve it? I am using last version of AngularJS 2
Upvotes: 1
Views: 133
Reputation: 64913
There is no property on NgModule where you can simply pass in the results of a call to provide
, you need to provide
as part of your providers array like so...
providers: [
AuthenticationService,
{ provide: CustomRequestOptions, useClass: CustomRequestOptions }
]
Upvotes: 1