Skip to content

Commit

Permalink
fix(kit): ComboBox throws `ExpressionChangedAfterItHasBeenCheckedEr…
Browse files Browse the repository at this point in the history
…ror`
  • Loading branch information
nsbarsukov committed May 17, 2022
1 parent dbf83f7 commit 8f66673
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions projects/kit/components/select-option/select-option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ export class TuiSelectOptionComponent<T> implements OnInit {
}

ngOnInit(): void {
if (isPresent(this.option.value) && this.host.checkOption) {
this.host.checkOption(this.option.value);
}
/**
* This would cause changes inside already checked parent component (during the same change detection cycle),
* and it might cause ExpressionChanged error due to potential HostBinding
* (for example, inside {@link https://github.com/angular/angular/blob/main/packages/forms/src/directives/ng_control_status.ts#L99 NgControlStatus}).
* Microtask keeps it in the same frame but allows change detection to run.
*/
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Promise.resolve().then(() => {
if (isPresent(this.option.value) && this.host.checkOption) {
this.host.checkOption(this.option.value);
}
});
}

protected get selected(): boolean {
Expand Down

0 comments on commit 8f66673

Please sign in to comment.