angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.34k stars 6.74k forks source link

Autocomplete observable async error #3243

Closed ask007learning closed 7 years ago

ask007learning commented 7 years ago

Bug, feature request, or proposal:

Bug

What is the expected behavior?

To handle observable

What is the current behavior?

Throws the following error: Cannot find a differ supporting object '[object Object]' of type 'object'

What are the steps to reproduce?

https://plnkr.co/edit/YQ5dLMXChxnLM7bRWMl7?p=preview

Which versions of Angular, Material, OS, browsers are affected?

material: 2.0.0-beta.2

willshowell commented 7 years ago

The issue is your use of map here:

this.autoCompleteList  = this.searchCtrl.valueChanges
  .startWith(null)
  .map(txt => this.filterSearchResults(txt))

Instead, you should be using switchMap.

To get your plunker to work, you'll need to make the switchMap change as well as these:

import 'rxjs/add/observable/from';

...

filterSearchResults(val: string){
  return val ? this.getResults(): Observable.from([]);
}
kara commented 7 years ago

Thanks for looking into it, @willshowell! It does look like switchMap would be more appropriate here. ngFor + the async pipe expects the bound observable to emit iterables, not nested observables. Closing, as it works as intended.

angular-automatic-lock-bot[bot] commented 5 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.