我已经实现了这个功能:
public deleteCards(user: string, tokens: Array<string>, extraHttpRequestParams?: any): Observable<{}> {
return this.deleteCardsWithHttpInfo(user, tokens, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
} else {
return response.json();
}
}).catch((error: any) => {
if (error.status >= 500) {
return Observable.throw(new Error(error.status));
}
else { //if (error.status >= 400) {
const body = error.json() || '';
const code = body.error || JSON.stringify(body);
const message = body.message || JSON.stringify(body);
return Observable.throw(ApiError.create(code, message));
}
});
}
如您所见,它会返回Observable<{}>
。我称之为:
this.deleteCards(action.payload.username, action.payload.tokens)
.map(() => { ((((1))))
return <Action>{
type: 'DELETE_CARDS_SUCCESS',
payload: action.payload.tokens
};
})
.catch(_ => {
return Observable.of(<Action>{ type: 'DELETE_CARDS_FAILED', payload: { }});
}));
然而,永远不会达到((((1))))
。
我也试过这个:
.map(_ => { ...
.map((p:any) => {...
但它永远不会到达。
答案 0 :(得分:0)
您必须订阅到observable才能执行任何操作:
this.deleteCards(...).map(...).catch(...).subscribe((action: Action) => {
// do something with the action.
});