I have issue with Observables. I have no trouble with basic communication e.g.: SERVICE:
getTableRecords(): Observable<RecordModel[]> {
return this.http
.get( this.API + 'records' )
.map( (tableRecords: Response) => tableRecords.json().data as RecordModel[] )
.catch(this.handleError);
}
COMPONENT:
getTableRecords() {
this.recordService.getTableRecords()
.subscribe( tableRecords => { this.tableRecords = tableRecords; }, (err) => { this.error = err; console.log(this.error)})
}
Example on top works well, but I have issue with one extra step. Before I'll display result, I wannt to filter one value based on parametr with communications between two services:
SERVICE I:
getTableRecords(): Observable<RecordModel[]> {
return this.http
.get( this.API + 'records' )
.map( (res: Response) => res.json().data as RecordModel[] )
.catch(this.handleError);
}
SERVICE II
getRecordDetail(assetId: string) {
return this.rootService.getTableRecords()
.map( (tableRecords:RecordModel[]) => {
console.log("GET RECORDS TO ANOTHER SERVICE: ", tableRecords, assetId);
(tableRecords:RecordModel[]) => tableRecords.filter( (tableRecord:RecordModel) => tableRecord.assetId === assetId )
})
}
COMPONENT:
tableRecord: RecordModel;
getRecordDetail() {
this.sub = this.activatedRoute.params.subscribe(
params => {
if (params[ 'assetId' ] != undefined) {
let assetId:string = params[ 'assetId' ]
this.complianceDetailService.getRecordDetail(assetId)
.subscribe( result => this.tableRecord = result )
} else console.log("UNDEFINED ASSETID");
}
);
}
In COMPONENT I have issue in .subscribe( result => this.tableRecord = result ) IDE yells that void is not assignable to type RecordModel.
Please explain I can make this sequence: First: Get data from one service, Two: Manipulate data in second service, Three: return data to component.
All of this I want to make with Observables, because same sequence I am able to make with Promises.
Best Regards Uland!