@ngrx/data - 在实体数据服务中传递附加参数或使用自定义函数?

问题描述

我正在尝试使用 ngrx/data 来处理我的一个模型上的 CRUD 操作,但由于它是“嵌套的”,我需要在 getById 方法中传递多个参数。有没有办法在数据服务(它扩展认数据服务)中编写自定义函数,以便可以通过在我的组件中注入的实体服务访问它们?或者,ngrx/data的接口是否支持额外的参数?

    @Injectable()
export class AutomationEmailDataService extends DefaultDataService<AutomationEmail> {

  constructor(
    http: HttpClient,httpUrlGenerator: HttpUrlGenerator,private smService: SettingsManagerService
  ) {
    super('AutomationEmail',http,httpUrlGenerator);
  }

  // need to pass multiple keys here
  getById(automationId,emailId): Observable<AutomationEmail> {
    return this.http.get(AutomationsEndpoints.getAutomationEmailInfo(this.smService.getStoreId(),automationId,emailId))
      .map((res: AutomationEmail) => new AutomationEmail().deserialize(res));
  }

  // or,need a custom function that I can access through the entity service 
  getEmail(automationId,emailId): Observable<AutomationEmail> {
     // same http request here
  }

}

解决方法

getWithQueryEntityCollectionServiceBase 函数接受 QueryParams 作为参数。

所以在您的数据服务中:

getEmail(automationId,emailId) {

const params = new HttpParams().set("emailId",emailId).set("automationId",automationId);
this.getWithQuery(params);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...