I am following some Rx.Observable tutorials from an Angular 2 application and using the system autocomplete style.
When I enter into the field, the valueChanges event is fired from Angular 2 FormControl.
This is tied to an Observable, which makes an HTTP request against the JSON endpoint.
When the endpoint returns 404, the valueChanges event stops working.
I see an error in my subscription method, but am not quite sure what the best way to recover and continue.
I am also a bit confused why the KeyUp or ValueChange event will stop firing.
Change sample value - observed chain
this.userNameControl
.valueChanges
.do(r => {
console.log
}
)
.switchMap(userName => {
return this.getGitHubUser$(userName);
})
.catch(err => {
return Observable.of(err)
})
.subscribe(v => {
console.log(v);
},
(err) => {
console.log(err);
},
() => {
console.log('Complete');
});
getGitHubUser$(username) {
return this.http
.get(`https://api.github.com/users/${username}`)
}
HTML form management
<input type="text" [value]="userName" [formControl]="userNameControl" />
I tried to return Observable.empty () and Observable.never () in catch
.catch(err => {
return Observable.never();
})
, subscribe, complete, , Changes .