Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular ng-select and add event

I'm using ng-select and on selected item fire the callback which does some logic. I face the problem, that (add) event does not fire when I choose the item from the list and I use the (change) event instead. But if I use one item twice from the list the change event not fire, because it's a change event.

<ng-select 
    [clearSearchOnAdd]="true"
    (change)="changeLeagueOwner($event)"
    (add)="test()" ---> nothing here
    [clearable]="false"
    [items]="adminLeagueMembers"
    bindLabel="display_name">
</ng-select>
like image 458
Bogdan Tushevskyi Avatar asked Aug 06 '26 12:08

Bogdan Tushevskyi


2 Answers

change event only get triggered when the value changes. If you want to fire an event if the same item select twice then use the click function,

<ng-select 
    [clearSearchOnAdd]="true"
    (click)="changeLeagueOwner($event)"
    (add)="test()" ---> nothing here
    [clearable]="false"
    [items]="adminLeagueMembers"
    bindLabel="display_name">
</ng-select>
like image 111
Sachila Ranawaka Avatar answered Aug 08 '26 02:08

Sachila Ranawaka


Just for completion's sake, the reason why (add) is not working in your example is described in the documentation:

(add) is fired when item is added while [multiple]="true". Outputs added item

like image 44
Arnaud P Avatar answered Aug 08 '26 03:08

Arnaud P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!