Cha*_*sia 0 javascript observable rxjs typescript angular
getDetailsById(eId: number): Observable<Details> {
return this.api.post('detailsapi', cacheOptions, { Id: eId })
.pipe(
map((eDetails: any) => ({
id: eDetails.eId,
subDetails: this.mapSubDetails(eDetails.eSubDetails || [])
})),
catchError((err) => {
const template: Template = {
id: 0,
subEquipment: []
};
return Observable.throw(err)
})
);
}
Run Code Online (Sandbox Code Playgroud)
我想检查上面的代码是否eDetails为空。如果为空,那么我想停止 Observable.forkJoin.
您可以filter在pipe:
.pipe(filter(isNotNull))
Run Code Online (Sandbox Code Playgroud)
并使用 typeguard 相同:
export function isNotNull<T>(value: T): value is NonNullable<T> {
return value != null;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2547 次 |
| 最近记录: |