Gentlemen, please help me rewrite this method asynchronously so that the Observable> object is returned, and not just
ServiceResult.

public getAccount(login: string, password: string): ServiceResult<Account> { let token: string; let role: string; let code: number; this.http .post(this.url, new InputUser(login, password)) .subscribe((data: any) => { token = data.access_token; role = data.username; }, (error) => { code = error.statusCode }); var result = new ServiceResult<Account>(); if (code == 200) { result.data = new Account(token, role); } else { result.isError = true; } return result; } 

Thank.

  • one
    @overthesanity, in that example, there is no example with ovservable. Here, more than any flatMap would fit - Grundy

1 answer 1

 return this.http.post(this.url, new InputUser(login, password));