Skip to content

Commit 28cd5cb

Browse files
committed
fix: Move effect() calls to constructor to fix injection context error
1 parent e918191 commit 28cd5cb

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

src/lib/components/perfect-select/perfect-select.component.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,22 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnD
279279
private onChange: any = () => {};
280280
private onTouched: any = () => {};
281281

282+
constructor() {
283+
// Watch for options changes
284+
effect(() => {
285+
if (this.options.length > 0 && !this.loadOptions) {
286+
this.internalOptions.set([...this.options]);
287+
}
288+
});
289+
290+
// Update closeMenuOnSelect based on isMulti
291+
effect(() => {
292+
if (this.isMulti && this.closeMenuOnSelect === true) {
293+
this.closeMenuOnSelect = false;
294+
}
295+
});
296+
}
297+
282298
writeValue(value: any): void {
283299
this.internalValue.set(value);
284300
}
@@ -314,20 +330,6 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnD
314330
}
315331
});
316332
}
317-
318-
// Watch for options changes
319-
effect(() => {
320-
if (this.options.length > 0 && !this.loadOptions) {
321-
this.internalOptions.set([...this.options]);
322-
}
323-
});
324-
325-
// Update closeMenuOnSelect based on isMulti
326-
effect(() => {
327-
if (this.isMulti && this.closeMenuOnSelect === true) {
328-
this.closeMenuOnSelect = false;
329-
}
330-
});
331333
}
332334

333335
ngOnDestroy(): void {

0 commit comments

Comments
 (0)