0
I have a method that calls a service from an API and stores its result in a variable, but this result is not being assigned the variable I need.
atribuirImagem(): void {
this.imagemService.enviarArquivo(this.arquivoSelecionado)
.subscribe(
image => {
//Atribuindo valor
this.usuario.imagem = image;
});
}
I have another method to call a service that sends a user POST
by API. But in this user that I pass as parameter does not reach the variable that I assign in the other method.
cadastrarUsuario(): void {
this.ativarSpinner = true;
if(this.arquivoSelecionado != null){
this.atribuirImagem();
}
this.usuarioService.cadastrarNovoUsuario(this.usuario)
.subscribe(
ok => {},
err => {
this.mensagemValidacao = err.error;
});
this.ativarSpinner = false;
}
The user being passed as parameter does not have the value which was assigned in the other method. What is the problem in this case?
image => { console.log(image)} what is the printable value?
– veroneseComS
I suppose since the method is asynchronous, you will only get what you want if you put the registration snippet into the image => {
– veroneseComS
@veroneseComS the printable value is the name of the image itself.
– FelipeDwD
Probably your problem will be solved if you pass the registration contentNovUsuario inside your subscribe
– veroneseComS
@veroneseComS in the image case => { metodo(). That would be it?
– FelipeDwD
image => { this.usuarioService.cadastrarNovoUsuario...
– veroneseComS
@veroneseComS I did it this way, it worked, thank you.
– FelipeDwD