this.beds$ = this.wrcService.getWrcBedsByFilter(this.wrcId, workerTypeId, blockId, buildingId, floorId, ['100000002'])
.pipe(
tap(bedsResponse => console.log(bedsResponse)),
filter(bedsResponse => bedsResponse != null),
flatMap(beds => beds),
map(bed => {
bed.numberOfBedsArray = Array.from({length: bed.qty}, (v, i) => i + 1);
return bed;
}),
mergeMap(beds => beds)
);
bedsResponse
is of type Observable<Bed[]>
flatting
it to each Bed object
this.wrcService.getWrcBedsByFilter().pipe(map(beds => beds.map(...)))
should be enough right?
//set id if present
this.route.queryParams
.pipe(
map(param => param['id'])
)
.subscribe(paramValue => {
this.contractId = paramValue;
});
The same way I need to check for applicationId
var idQueryParamObs = this.route.queryParams
.pipe(
filter(param => param['id'] != null),
map(param => param['id'])
);
var applicationIdQueryParamObs = this.route.queryParams
.pipe(
filter(param => param[applicationId'] != null),
map(param => param['applicationId'])
);
Connecting to dev server
at the bottom after I hit Run this project button.
ngOnInit() {
this.id$ = this.route.queryParams.pipe(map(params => params.id)); //<---- why no filter here
this.applicationId$ = this.route.queryParams.pipe(
filter(params => !!params.appId), //<----- but here any intended purpose of this?
map(params => params.appId)
);
const combinedIds$ = combineLatest([
this.id$.pipe(filter((id: string) => id !== null)), // and then here
this.applicationId$.pipe(
filter((applicationId: string) => applicationId !== null)
)
]);
this.result$ = combinedIds$.pipe(
map(([id, applicationId]: [string, string]) => ({
id,
applicationId
}))
);
this.result$.subscribe(result => {
console.log({ result });
});
}
}
Project
function it expects. I am never able to implement it.
//set id if present
var idParam = this.route.queryParams
.pipe(
filter(params => !!params.id),
map(params => params.id)
);
var applicationParam = this.route.queryParams
.pipe(
filter(params => !!params.applicationId),
map(params => params.applicationId)
);
const combined = combineLatest([
idParam.pipe(filter((id: string) => id !== null)),
applicationParam.pipe(
filter((applicationId: string) => applicationId !== null)
)
]).pipe(
map(([id, applicationId] : [string, string]) => ({
id,
applicationId
}))
);
var result = combined.pipe(
switchMap(result => {
})
);
result.subscribe((contract: TenantContract) => {
});
I am getting an error in switchMap clause.