In my current project, I am developing a Meteor web application using Angular 2 and TypeScript. To interact with a REST API, I have utilized Swagger Codegen to generate client code. However, I am facing a challenge as there are no example implementations available on GitHub that demonstrate how to use the REST client effectively.
Within an Angular 2 view component, I have integrated an Angular 2 service (ProductTreeService) and the generated API (both annotated with "@Injectable"):
@Component({
selector: 'panel-product-selection',
template,
providers: [ProductTreeService, UserApi],
directives: [ProductTreeComponent]
})
export class PanelProductSelectionComponent
{
private categoriesProductsTree: Collections.LinkedList<CategoryTreeElement>;
private productTreeService: ProductTreeService;
private userApi: UserApi;
constructor(productTreeService: ProductTreeService, userApi: UserApi)
{
this.productTreeService = productTreeService;
this.userApi = userApi;
}
ngOnInit(): void
{
//...
}
}
While I have successfully accessed the angular service without any issues, the application encounters errors when attempting to inject UserApi. The main disparity between UserApi and ProductTreeService lies in their constructors: the service has no constructor parameters, whereas the generated API class includes:
constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string) {
if (basePath) {
this.basePath = basePath;
}
}
Therefore, I am seeking guidance on how to effectively inject the generated API into my application.