I'm new at angular and I have the following problem
When assigning response value to the variable of my service, that variable is presented in the chorme console as undefined
But in the subscribe method http the variable is with the assigned value of the response.
I'm not understanding the problem
@Injectable()
export class ControlService {
permissao: string;
constructor(
private httpConnection: HttpConnection,
private http: Http){}
getControl(){
if(localStorage.papel){
this.buscar('desconto', 'todos');
console.log('Permissão: ' + this.permissao);
}
buscar(desconto : string, todos : string){
return this.http.get('http://localhost:8080' + "/" + aplicacao + "/" + nome)
.subscribe((response) => {this.permissao = response.text(); console.log(this.permissao)});
}
}
the console.log inside busca method displays the value in the google chrome console, but the console inside the getControl method shows the value of the permissao variable as undefined