Form control required depending on the selection of another form control angle

1

I have the following mat-checkbox:

<mat-checkbox formControlName="formControlIdentificador" color="primary" class="correcaoClasseCheck" labelPosition="before"></mat-checkbox>

<input formControlName="formControlNomeIdentificador" matInput placeholder="Qual era o nome no identificador?">

The second input (formControlNameName) should be required if the checkbox is selected. How can I do this?

This is my form builder:

    this.secondFormGroup = this._formBuilder.group({

    formControlIdentificador: new FormControl('', [
    ]),

    formControlNomeIdentificador: new FormControl('', [
    ])

  });
    
asked by anonymous 12.11.2018 / 22:29

1 answer

0

I would try one of two ways: first

<input formControlName="formControlNomeIdentificador" matInput placeholder="Qual era o nome no identificador?" [required]="secondFormGroup.get('formControlIdentificador').value">

Or:

<input formControlName="formControlNomeIdentificador" matInput placeholder="Qual era o nome no identificador?" [required]="!secondFormGroup.valid">
    
16.11.2018 / 23:51