I faced with difficulties for getting values from async queries using Observable in Angular 5
export class CustomComponent {
private external: any;
constructor(private http: HttpClient) {}
getContent() {
return this.http.get('api/conten/get');
}
retrieve() {
this.getContent().subscribe(content => {
this.external = content;
console.log(this.external) // here we get content that we expect
});
console.log(this.external); // there is 'undefined'
}
}
How can I set external variable with result from getContent()?
Probably there are other ways?
I guess this situation very frequent when we need to use response in code bellow
Please, give example how can I get value from response immediately after request(e.g. make request sync within the framework of Angular)