Angular 7 waiting Service reply to continue
Good Afternoon, folks, I own two methods, how do I wait for a method that is calling an external service to respond to continue executing the method that called that method? Example:
salvarUsuario(){
this.usuario = formUsuario.value();
this.pegarEndereco(this.usuario.cep);
this.usuarioService.salvar().subscribe();
}
pegarEndereco(cep: string){
this.cepService.buscarPorCep(cep).subscribe((response: any) => {
this.usuario.endereco = response;
});
}
In this case, I only want to continue the execution after the pick () address responds.
Note: I did not want to make the call inside the cepService subscribe.search bycep (cep)
0
Author: Felipe Denardo, 2019-04-03
1 answers
You can make a " subscribe "in the" getdirectory " function within the user save.
salvarUsuario(){
this.usuario = formUsuario.value();
this.pegarEndereco(this.usuario.cep).subscribe(success -> {
this.usuarioService.salvar().subscribe();
}, error -> {
fazerAlgumaCoisa();
});
}
pegarEndereco: any(cep: string){
return this.cepService.buscarPorCep(cep);
}
2
Author: Eder Rodrigues, 2019-04-04 15:24:51