Angular 4 http批处理请求
为了优化API调用,我想使用此模块发出批处理请求 . 根据示例,配置在AppModule中设置Angular 4 http批处理请求,angular,http,angular2-template,angular2-services,Angular,Http,Angular2 Template,Angular2 Services,为了优化API调用,我想使用此模块发出批处理请求 . 根据示例,配置在AppModule中设置 export function httpBatchConfigurationFactory() { return new HttpBatchConfigurationCollection([ new HttpBatchConfiguration({ rootEndpointUrl: "https://api.myservice.com", batchEndpoint
export function httpBatchConfigurationFactory() {
return new HttpBatchConfigurationCollection([
new HttpBatchConfiguration({
rootEndpointUrl: "https://api.myservice.com",
batchEndpointUrl: "https://api.myservice.com/$batch"
})]);
};
在提供者中,我设置了
{ provide: HttpBatchConfigurationCollection, useFactory: httpBatchConfigurationFactory },
{ provide: Http, useClass: HttpBatcher }
当此配置为静态时,一切正常。
我的应用程序仅在用户登录到应用程序后才识别rootEnPointUrl
在用户身份验证之后,如何向此HttpBatchConfigurationCollection添加新的HttpBatchConfiguration?为什么不使用可注入服务,而不是在模块设置期间提供工厂?这样,即使在应用程序初始化之后,您也可以随时更改配置。为什么不使用可注入服务,而不是在模块设置期间提供工厂?这样,即使在应用程序初始化之后,您也可以随时更改配置。@Xinan确实是一个简单的http批处理集合注入工作。@Xinan,请添加您的评论作为答案,否则我将添加到这里:@nkuma_12感谢您的提醒^^