Reputation: 1363
I add @ngrx/data in my application. My problem is I have to get data from other entities as well to add to the HTTP call. My code is like
export class ReportsModule {
entityMetaDataMap: EntityMetadataMap = {
FormAData: { },
FormBData: {},
DataReport: {}
};
constructor(
private entityDefinitionService: EntityDefinitionService,
private entityDataService: EntityDataService,
private dataReportService: DataReportService,
) {
entityDefinitionService.registerMetadataMap(this.entityMetaDataMap);
entityDataService.registerServices({ 'DataReport': dataReportService});
}
}
My custom data service
@Injectable()
export class ReportDataService extends DefaultDataService<DataReport> {
constructor(
private httpClient: HttpClient,
httpUrlGenerator: HttpUrlGenerator,
private formA: FormAEntityService,
private formB: FormBEntityService
) {
super('DataReport', httpClient, httpUrlGenerator)
}
getAll(): Observable<DataReport[]> {
return this.formA.entities$.pipe(
withLatestFrom(this.formB.entities$),
switchMap(([formA, formB]) => {
return this.dataReport.getReportSummary(
formA['station'],
// other fields from form A goes Here
formB['name'],
// other fields from form B goes here
).pipe(
map((response: DataReportResponse) => response.dataReport)
)
}))
}
}
How to get info from other entities in my ReportDataService? If I remove formA and formB entity service from constructor, I'm not getting any errors, otherwise, I'm getting
Error No Entity definition for FormAData and FormBData
FromA and FormB entity services are working fine in their respective components. Please help me to solve this issue. Thanks in advance.
Upvotes: 0
Views: 174