Skip to content

Commit 8b8874b

Browse files
committed
fix(custom-select): Fix custom select emits the event on model changed outside
1 parent 90caeef commit 8b8874b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

projects/angular-editor/src/lib/ae-select/ae-select.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export class AeSelectComponent implements OnInit, ControlValueAccessor {
6464

6565
optionSelect(option: SelectOption, event: MouseEvent) {
6666
event.stopPropagation();
67-
this.writeValue(option.value);
67+
this.setValue(option.value);
68+
this.onChange(this.selectedOption.value);
69+
this.changeEvent.emit(this.selectedOption.value);
6870
this.onTouched();
6971
this.opened = false;
7072
}
@@ -94,19 +96,21 @@ export class AeSelectComponent implements OnInit, ControlValueAccessor {
9496
}
9597

9698
writeValue(value) {
97-
let index = 0;
9899
if (!value || typeof value !== 'string') {
99100
return;
100101
}
102+
this.setValue(value);
103+
}
104+
105+
setValue(value) {
106+
let index = 0;
101107
const selectedEl = this.options.find((el, i) => {
102108
index = i;
103109
return el.value === value;
104110
});
105111
if (selectedEl) {
106112
this.selectedOption = selectedEl;
107113
this.optionId = index;
108-
this.onChange(this.selectedOption.value);
109-
this.changeEvent.emit(this.selectedOption.value);
110114
}
111115
}
112116

0 commit comments

Comments
 (0)