I am extending BaseRequestOptions
in Angular2 to add headers for each request. I also have a Config
class that supplies key/value pairs based on the domain, which I need to inject into my derived class:
import { BaseRequestOptions } from '@angular/http';
import { Config } from '../../config/configuration';
export class DefaultRequestOptions extends BaseRequestOptions {
constructor(private config: Config) {
super();
Object.keys(this.config.api.headers).map((key) => {
this.headers.append(key, this.config.api.headers[key]);
});
}
}
In my module, I am specifying the provider as such:
@NgModule({
. . .,
providers: [
. . .,
{ provide: RequestOptions, useClass: DefaultRequestOptions }
]
})
. . .
The problem I'm having is that this.config
is undefined
in DefaultRequestOptions
. I am also using the Config
class as an injected dependency in other classes, so I'm confident it's working as expected, and if I manually set the values for this.headers
everything works fine.
What am I doing wrong that would cause the config to be undefined in DefaultRequestOptions
?