I keep encountering an undefined value when trying to assign the subscribed value to a variable in my code snippet below.
service.ts
getIpAddress() : Observable<any>
{
return this.http
.get(this.Geo_Api)
.map((response: Response) => { return <any>response.json()
} )
.catch(this.handleError);
}
component.ts
constructor(private apiservice: ApiService )
{
this.getIpAddress();
}
ngOnInit() { console.log(this.client_ip$); }
getIpAddress()
{
this.apiservice.getIpAddress()
.subscribe(data => {
this.client_data$ = data.ip;
this.client_ip$ = this.client_data$;
});
}