我试图使用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
}
}
EntityCollectionServiceBase
的getWithQuery
函数接受QueryParams
作为参数。
那么在data service中:
getEmail(automationId, emailId) {
const params = new HttpParams().set("emailId", emailId).set("automationId", automationId);
this.getWithQuery(params);