У меня есть внешняя заявка на мой класс обслуживания
public getEndereco(cep: string){
return this.http.get("http://viacep.com.br/ws/" + cep + "/json",{
responseType: 'text'
});
}
После этого я ловлю возвращаемый json и помещаю в объект мой класс Util
public getEndereco(cep: string): Endereco{
let endereco = new Endereco();
this.serviceUtil.getEndereco(cep)
.subscribe((response)=>{
let json = JSON.parse(response);
endereco.cep = json.cep;
endereco.rua = json.logradouro;
endereco.complemento = json.complemento;
endereco.bairro = json.bairro;
endereco.cidade = json.localidade;
endereco.estado = this.buscarEstadoSigla(json.uf);
},(erro)=>{
console.log(erro);
});
return endereco;
}
В моем слоеВидение, я получаю этот объект и делаю это:
private getEndereco(){
this.endereco = this.util.getEndereco(this.endereco.cep);
this.estado = this.endereco.estado;
}
Но всегда "this.endereco.estado" приходит в ноль.Я знаю угловую работу с асинхронным.Как я могу ожидать, что объект "this.endereco" вернется из возврата после присваивания в качестве нижней строки?