Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

How to synchronise http.client request observable using url suffix drawn from storage

$
0
0

HI there,

(first time posting - please go easy on me!).

I’m struggling with what I imagine might be a simple problem to fix hitting a wall here if anyone can help please.

I have an ionic app which asks the user to input a city, and that is put into storage. This is on another page, I have it so that the stored value will be added to the prefix of a url string and called in a http request to an API.

While both work individually, when trying to get them to work together I’m having difficult. I’m not sure whether its a question of relying on lifecycle hooks or using synchronous keywords. I’ve tried playing with both but I really think I’m not quite understanding each as both either to not update or draw an error.

At the moment, I’ve housed the code in a provider.

Any help?

@Injectable()
export class CitiesProvider {

  constructor(public http: HttpClient, private storage: Storage) {
 
  }

url: string = "https://restcountries.com/v3.1/capital/";
cityCap: string;



    getCities(): Observable<any>{
	
  this.storage.get("cityChoice")
.then((val) => {
console.log
	this.cityCap = val;
})
.catch((error) => {
	alert("Error accessing Storage")
});

  return this.http.get(this.url + this.cityCap );
  
  }
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles