1

我正在尝试使用 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
  }

}
4

1 回答 1

0

接受作为参数的getWithQuery功能。EntityCollectionServiceBaseQueryParams

所以在你的数据服务中:

getEmail(automationId, emailId) {

const params = new HttpParams().set("emailId", emailId).set("automationId", automationId);
this.getWithQuery(params);
于 2021-02-01T08:38:07.557 回答