Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 4 http批处理请求_Angular_Http_Angular2 Template_Angular2 Services - Fatal编程技术网

Angular 4 http批处理请求

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

为了优化API调用,我想使用此模块发出批处理请求 . 根据示例,配置在AppModule中设置

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感谢您的提醒^^