Skip to content

Commit ba80ab8

Browse files
committed
feat(toggle): add change detection
1 parent b5d2785 commit ba80ab8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

projects/components/src/toggle-switch/toggle-switch.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
22
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
33
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
44
import { ToggleSwitchSize } from './toggle-switch-size';
@@ -54,6 +54,8 @@ export class ToggleSwitchComponent implements ControlValueAccessor {
5454
private onTouched!: () => void;
5555
private onChanged!: (value: boolean) => void;
5656

57+
public constructor(private readonly cdr: ChangeDetectorRef) {}
58+
5759
public onToggle(toggleChange: MatSlideToggleChange): void {
5860
this.isChecked = toggleChange.checked;
5961
this.checkedChange.emit(this.isChecked);
@@ -71,9 +73,11 @@ export class ToggleSwitchComponent implements ControlValueAccessor {
7173

7274
public setDisabledState(isDisabled: boolean): void {
7375
this.isDisabled = isDisabled;
76+
this.cdr.markForCheck();
7477
}
7578

7679
public writeValue(isChecked: boolean | undefined): void {
7780
this.isChecked = isChecked ?? false;
81+
this.cdr.markForCheck();
7882
}
7983
}

0 commit comments

Comments
 (0)