I have call api from http.get method and need to return response but problem is that next step evaluate first. like in my service.ts file
public mydata:any;
constructor(private http:Http)
getSettings()
{
this.http.get("http://localhost:60599/api/export/settings?api_key=1234567928682345")
.map(res=>res.json())
.subscribe((res) =>
{
mydata=res;
//second
console.log((mydata);
});
//first
console.log(this.mydata);
}
but its in #first that evaluate null or undefined value and I need to return it and get that value in my component. in #second comments when I print mydata it prints but after not what is the reason behind this login and how first evaluate and return value.