I'm using Google's places api - getPlacePredictions
.
Here is my code on my input keyup event:
My template:
<input type="text" (keyup)='search()'>
<div *ngIf="searching">Searching ... </div>
My Class:
private autocomplete;
ngAfterViewInit () {
this.autocomplete = new google.maps.places.AutocompleteService();
}
search(){
this.searching = true;
this
.autocomplete
.getPlacePredictions( option , ( places , m )=> {
console.log( 'onPrediction' , places );
this.searching = false;
} );
}
Is there any practicable way to wrap getPlacePredictions, inside a rxjs observable so I can take advantage of subscribing to this function ?
What I'm trying to do eventually here is to create a loading icon visible and invisible, but I can't make it properly with the google's api itself, I guess if I could wrap it inside an Observable, it would become easy.
next()
to emit data. Have components subscribe to changes. – Fulkerson