@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
}
}

EntityCollectionServiceBasegetWithQuery函数接受QueryParams作为参数。

那么在data service中:

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

相关内容

  • 没有找到相关文章

最新更新