error-state-Dtb1IHM-.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Class that tracks the error state of a component.
  3. * @docs-private
  4. */
  5. class _ErrorStateTracker {
  6. _defaultMatcher;
  7. ngControl;
  8. _parentFormGroup;
  9. _parentForm;
  10. _stateChanges;
  11. /** Whether the tracker is currently in an error state. */
  12. errorState = false;
  13. /** User-defined matcher for the error state. */
  14. matcher;
  15. constructor(_defaultMatcher, ngControl, _parentFormGroup, _parentForm, _stateChanges) {
  16. this._defaultMatcher = _defaultMatcher;
  17. this.ngControl = ngControl;
  18. this._parentFormGroup = _parentFormGroup;
  19. this._parentForm = _parentForm;
  20. this._stateChanges = _stateChanges;
  21. }
  22. /** Updates the error state based on the provided error state matcher. */
  23. updateErrorState() {
  24. const oldState = this.errorState;
  25. const parent = this._parentFormGroup || this._parentForm;
  26. const matcher = this.matcher || this._defaultMatcher;
  27. const control = this.ngControl ? this.ngControl.control : null;
  28. const newState = matcher?.isErrorState(control, parent) ?? false;
  29. if (newState !== oldState) {
  30. this.errorState = newState;
  31. this._stateChanges.next();
  32. }
  33. }
  34. }
  35. export { _ErrorStateTracker as _ };
  36. //# sourceMappingURL=error-state-Dtb1IHM-.mjs.map