Skip to content

Instantly share code, notes, and snippets.

@dmitry-stepanenko
Last active September 14, 2022 06:35
Show Gist options
  • Save dmitry-stepanenko/e5d7b941ad8bdd5340de023089dfbfd2 to your computer and use it in GitHub Desktop.
Save dmitry-stepanenko/e5d7b941ad8bdd5340de023089dfbfd2 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, false);
this._cdr.markForCheck();
}
protected setValue(value: number, emitEvent: boolean) {
this.value = value;
if (emitEvent && 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