4

form: FormGroup;

  createMyForm() {
    this.form = new FormGroup<any>({
      firstName: new FormControl<any>('', [Validators.required]),
      lastName: new FormControl<any>('', { nonNullable: true }),
    });
  }

How to add { nonNullable: true } to firstName

I am trying to add {nonNullable: true } to the form control.

lastName: new FormControl('', { nonNullable: true }),

I am able to add {nonNullable: true } to the control which doesnt have validations, but for the form control which has validations I am not able to add {nonNullable: true }.

firstName: new FormControl('', [Validators.required]),

gbr
  • 65
  • 5

1 Answers1

4
createMyForm() {
    this.form = new FormGroup<any>({
      firstName: new FormControl<any>('', {
        nonNullable: true,
        validators: [Validators.required]
      }),
      lastName: new FormControl<any>('', { nonNullable: true })
    });
  }

if all fields has nonNullable:true and you are comfortable injecting form-builder, you can use NonNullableFormBuilder

Amit Kumar
  • 620
  • 4
  • 17