Several examples demonstrate how to use observables to hook up a control to show data fetched from a http backend, such as this one: http://blog.thoughtram.io/angular/2016/01/06/taking-advantage-of-observables-in-angular2.html
Can you prevent that http call in certain situations? For example in the mentioned post there is an autocomplete field - is there a way to prevent the http call in case the user clears the field?
I have tried modifying the switchMap function with for example:
if(term.length < 1) {
return Observable.empty();
}
else { // call the http service...
and it does prevent the call, but leaves the previous results at the control.
Observable.emptycreates andObservablethat never fires. You need one that fires with an empty array to clear the list.