我正在使用Angular 2和TypeScript处理Meteor Web应用程序.对于使用REST API,我使用Swagger Codegen生成了客户端代码.不幸的是,GitHub上没有样本,如何使用其余的客户端.
我有一个角度2视图组件,它注入一个Angular 2服务(ProductTreeService)和生成的API(都标记为"@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
{
//...
}
}
Run Code Online (Sandbox Code Playgroud)
虽然角度服务只是可访问的并且一切正常,但是当我注入UserApi时应用程序崩溃了.UserApi和ProductTreeService之间的唯一区别是构造函数:服务没有构造函数参数,生成的Api类具有:
constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string) {
if (basePath) {
this.basePath = basePath;
}
}
Run Code Online (Sandbox Code Playgroud)
那么我该如何注入生成的API呢?