Skip to content

Instantly share code, notes, and snippets.

@dmitry-stepanenko
Last active September 14, 2022 06:35
Show Gist options
  • Save dmitry-stepanenko/4a94a4ed4399f70a47ceb65a369efbaf to your computer and use it in GitHub Desktop.
Save dmitry-stepanenko/4a94a4ed4399f70a47ceb65a369efbaf to your computer and use it in GitHub Desktop.
// ... code of CounterComponent
writeValue(value: number) {
// it's convenient to reuse existing "setValue" method, right?
// however, this will lead to the incorrect behavior
this.setValue(value);
this._cdr.markForCheck();
}
protected setValue(value: number) {
const parsed = parseInt(value as any);
this.value = isNaN(parsed) ? 0 : parsed;
if (this.onChange) {
this.onChange(value);
this.onTouched();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment