У меня проблема с возвратом. Наблюдается со второго запроса. Что-то вроде этого:
commandRequest(action:string, commandData:any):Observable<CashDesckResponse>
{
let command:CashDeskRequest;
//ask my backend for command
this.requestCommandString(action, commandData, "POST")
//this is my response from backend
.map(r=>r.response).subscribe(my_1_response=>{
//then i need to send this response data to other server/action
//to execute it and return this second response as the result of
//this method.
command = new CashDesckRequest(my_1_response);
return this.server.executeCommand(command).map(return_this=>return_this);
});
};
private requestCommandString(action:string, requestData:any,
type:string):Observable<AjaxResponse>{
return Observable.ajax({
body:JSON.stringify(requestData),
method:type,
url:this._apiServerUrl+action
}).map(r=>r);
};
Моя проблема в том, что commandRequest возвращает значение из первого.map(). И если я попытаюсь вернуть значение из внутренней ошибки компилятора компиляции: [ts] Функция, объявленный тип которой не является ни "void", ни "any", должна возвращать значение. https://habrastorage.org/web/93b/e6b/17b/93be6b17bf5b46b5847e67deefd6eea1.png
Для отображения из одного потока в другой вы можете использовать mergeMap или switchMap
commandRequest(action:string, commandData:any):Observable<CashDesckResponse>
{
return this.requestCommandString(action, commandData, "POST")
.map(r1 => new CashDesckRequest(r1.response)
// map first response to command instance
.mergeMap(command =>this.server.executeCommand(command));
// map the command observable to a new observable
}