Gregor Sklorz
Gregor Sklorz

Reputation: 170

primeng autocomplete no onSelect event on click

I expected that the PrimeNG AutoComplete component is emitting the (onSelect) event on and on Keyboard select. But it emits only Keyboard selection. While "[dropdown]=false"

The Example is very simple:

<p-autoComplete ... (onSelect)="onSelect()" ...>

...

onSelect(){
    console.log('select', this.suggestions);
  }

using: "primeng": "^6.1.4", "@angular/cli": "^6.2.3",

How do I catch a clicked selection on auto-complete suggestions?

Or even better: How can I achieve the "DropdownButton-click" behavior on "InputField-click"? Just to get rid of the dropdown button but keep the behavior.

EDIT:

Its similar to this case, but it doesnt helps me for the Angular way.

Primefaces Autocomplete - How to display dropdown items on click of input

Upvotes: 1

Views: 17617

Answers (3)

Mirlo
Mirlo

Reputation: 674

You just need to remove the [(ngModel)]="selectedIem"

Upvotes: 0

Pierre
Pierre

Reputation: 2912

I confirm that this works for me on Angular8/PrimeNG8 ("primeng": "^8.0.0", "@angular/cli": "^8.3.25"). Both when selecting using the mouse or the keyboard: the onSelect gets triggered.

Make sure you pass the event as well:

<p-autoComplete ... (onSelect)="onSelect($event)" ...>

...

onSelect(event: any){
    console.log( event );
  }

Check "frosty"'s solution/stackblitz. That works.

Upvotes: 4

frosty
frosty

Reputation: 21762

I was able to get this to work in a stack blitz. The onSelect works, as well as the completeMethod works.

https://stackblitz.com/edit/angular-7komnz

Upvotes: 3

Related Questions