I have a group dropdown, and when selecting from the drop down the first time, the startWith value is always null. Why is this happening? In subsequent selection from dropdown, startWith() gets the right value.
So selecting from dropdown drives this list.
My template looks something like this:
<person-list
[list]=list$
</person-list>
My component class
ngOnInit() {
list$ = this.getNames();
}
getNames():Observable<Name[]> {
return formControl.valueChanges.pipe(
startWith(formControl.value),
switchMap(group => {
return http.getNames();
})
)}
CodePudding user response:
I believe you should just subscribe your Observable this.getNames().subscribe(names => list$=names)
CodePudding user response:
Need context in this question. Because initially formControl.value might be undefined. Make sure to patch the value first to formControl.value. By the way you can just test without formControl, just use startWith('query').