If you want to introduce basePath in the MyApi class, you can do this as shown below
Add the path provider to the application providers and use the @Inject('path') parameter decorator to enter it in the MyApi class
@Injectable() export class MyApi { protected basePath = 'https://localhost/'; public defaultHeaders : Headers = new Headers(); constructor(protected http: Http, @Inject('path') basePath: string) { if (basePath) { this.basePath = basePath; } } }
Than in the boot file of your application (@NgModule)
bootstrap('name of your app.component class', [ MyApi, provide('path', { useValue: 'any value which you want to inject'}) ]);
you can use the @Optional parameter to make the dependency optional.
source share