sorry if this was asked already, I couldn’t find a similar question that had a satisfactory answer or had an answer that wasn’t deprecated. I’m not really sure how to word what I am trying to do in any technical way, I am still very new to web development.
Essentially I am trying to assign data from a GET request to a variable. I understand that an HttpClient GET request returns an Observable that must be subscribed to. The following works, it prints the correct data (a Json object):
this.get("").subscribe(response => {console.log(response)});
However when I try to assign response to a variable:
let raw; //have also tried var as I thought it might be related to scope?
this.get("").subscribe(response => {raw = response});
console.log(raw) //returns undefined
let raw = this.get("").subscribe(response => response); //have also tried => response.data with same result
console.log(raw) //returns a weird object that I assume is the observer?
What is the best way to do this? Thanks in advance.