I am using angular 5 and I have installed the httpClient Module so I can get data from an api.
On my app.component.ts I have this:
getData() {
this.http.get('url to get xml data from', { responseType: 'text' }).subscribe(data => {
return data;
});
}
What I need to do it to call this method from my ngOnInit so that I can use the data outside the method so I tried this:
ngOnInit() {
this.result = this.getData();
}
But the above is not giving me the data so what I'm I missing for this to work with Angular?