FormControlDirective: NgOnChanges calls updateValueAndValidity w/ emitEvent:false. (Async)Validators dont trigger statusChanges. Why not configurable?

Viewed 14

The FormControlDirective calls in its ngOnChanges the updateValueAndValidity method with emitEvent:false. Hence, if SyncValidators do not already produce errors AsyncValidators are called. However, the async result of these operators does not trigger a statusChanges-event. Why is this behavior not configurable? I imagine there are plenty of cases where one could readonable argue it is desired to be informed about the async validators results by listening to the statusChanges observable.

  ngOnChanges(changes: SimpleChanges): void {
    if (this._isControlChanged(changes)) {
      const previousForm = changes['form'].previousValue;
      if (previousForm) {
        cleanUpControl(previousForm, this, /* validateControlPresenceOnChange */ false);
      }
      setUpControl(this.form, this);
      **this.form.updateValueAndValidity({emitEvent: false});**
    }

In the case where AsyncValidator produces an error, the setError would be called with emitEvent set to false. Hence not triggering a statusChanges event.

  setErrors(errors: ValidationErrors|null, opts: {emitEvent?: boolean} = {}): void {
    (this as {errors: ValidationErrors | null}).errors = errors;
    this._updateControlsErrors(opts.emitEvent !== false);
  }
0 Answers
Related