Implementing a custom feature, I have chosen to extend BaseRequestOptions
in Angular2 to incorporate headers for every request. Additionally, I have introduced a Config
class that offers key/value pairs specific to the domain, which must be injected 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]);
});
}
}
Within my module setup, the provider is defined as follows:
@NgModule({
. . .,
providers: [
. . .,
{ provide: RequestOptions, useClass: DefaultRequestOptions }
]
})
. . .
An issue arises where this.config
is being identified as undefined
inside DefaultRequestOptions
. Despite having used the Config
class successfully as an injected dependency in other areas, setting values manually for this.headers
solves the problem.
What could be causing the configuration to be undefined within DefaultRequestOptions
?