rbaumi / angular2-select

An implementation of material design select element for Angular 2
MIT License
6 stars 1 forks source link

Custom 'remove' event #3

Open askaFed opened 7 years ago

askaFed commented 7 years ago

I have multiple select components. If I click 'remove' in one of them, I want to remove values from some other select components. Could you give me some advice how to do this?

rbaumi commented 7 years ago

Hi @askaFed. Sorry for late reply - I was on holiday. When you click 'remove' on one of the selector it emits the selectionChanged event with param null. What you can do is:

<bm-ng2-select
    placeholder="Select a country"
    (selectionChanged)="onSelectionChange($event);">
    <bm-ng2-option value="PL">Poland</bm-ng2-option>
    <bm-ng2-option value="US" disabled="true">USA</bm-ng2-option>
    <bm-ng2-option value="DK" selected="true">Denmark</bm-ng2-option>
    <bm-ng2-option value="FR">France</bm-ng2-option>
</bm-ng2-select>

now in your component you can do:

private onSelectionChange(value: string) {
   if (null === value) {
      // remove button was pressed

   }
}