Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the sugestions through an event #973

Closed
kavi87 opened this issue Nov 30, 2018 · 3 comments · Fixed by #1081
Closed

Expose the sugestions through an event #973

kavi87 opened this issue Nov 30, 2018 · 3 comments · Fixed by #1081

Comments

@kavi87
Copy link

kavi87 commented Nov 30, 2018

When searching for an element, I'd like to retrieve the list of sugestions that match the search filter.

Why ? I'd like to offer an alternative to the user if the result is empty.

@smithk58
Copy link

smithk58 commented Dec 5, 2018

I think you could solve this using the typeahead (similar to how they do it in the demo: https://github.com/ng-select/ng-select/blob/master/demo/app/examples/search.component.ts).

With the typeahead being used in your [items] call you can pretty much have full control over whatever you want to do to the items before they're displayed in the control.

For example, I didn't want it to spam my backend too much, so I took their example and modified it to return an empty list if the search term is too short or if it's not defined.

this.searchMembersTerm$.pipe(
        debounceTime(500),
        distinctUntilChanged(),
        switchMap(term => {
          // Return empty list if no search term or < 2 characters, otherwise execute member search
          if (!term || term.length < 2) {
            return of([]);
          } else {
            this.searchLoading = true;
            return obfuscatingMyService.pipe(
              catchError(() => of([])), // empty list on error
              tap(() => this.searchLoading = false)
            );
          }
        })
      )

@ratiuandreea
Copy link

Is there a way to make loading specific to an input? I have to loop through an array and show 8 inputs let's say. This searchLoading is general for any input and the loading icon appears on each of the 8 inputs from the for loop.

@benj0c
Copy link

benj0c commented Aug 26, 2019

Features like this one, you should put in changelog file as breaking changes or am I wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants