Angular formGroup内formArray内的验证控制

Angular formGroup内formArray内的验证控制,angular,typescript,angular-reactive-forms,Angular,Typescript,Angular Reactive Forms,如何验证formGroup中的控件,而formGroup又在数组中 在这种情况下,我想验证Numerocellar 我有以下资料: 组件。ts this.formContacto = this.fb.group({ telefonos: this.fb.array([ this.fb.group({ tipo: [''], numeroCelular: ['', Validators.required],

如何验证formGroup中的控件,而formGroup又在数组中

在这种情况下,我想验证Numerocellar

我有以下资料:

组件。ts

    this.formContacto = this.fb.group({
      telefonos: this.fb.array([
        this.fb.group({
          tipo: [''],
          numeroCelular: ['', Validators.required],
          whatsapp: [],
          codigoCiudad: [],
          numeroFijo: [],
        })
      ])
    });

    errorNumeroCelular(i) {
      return ((this.formContacto.controls['telefonos'] as FormGroup) as 
      FormGroup).controls.numeroCelular.hasError('required') ? 'Ingrese un número de celular' : '';
    }
components.html

<mat-form-field appearance="standard">
  <mat-label>Número celular</mat-label>
  <input matInput formControlName="numeroCelular">
  <mat-error *ngIf="errorNumeroCelular()">{{errorNumeroCelular()}}</mat-error>
</mat-form-field>

努梅罗·塞卢拉
{{errorNumeroCelular()}}
试试这个

this.formContacto = this.fb.group({
  telefonos: this.fb.array([
    [this.createNewFormGroup()],
    [Validators.required])
  ])
});
createNewFormGroup()
方法正在创建一个FormGroup,如下所示

createNewFormGroup() {
    return this.fb.group({
      tipo: [''],
      numeroCelular: ['', Validators.required],
      whatsapp: [],
      codigoCiudad: [],
      numeroFijo: [],
    })
} 
访问FormArray的验证状态

get yourName(): FormArray {
    return this.formContacto.get('telefonos') as FormArray;
} 
HTML模板

<label *ngIf="telefonos.errors?.required">
  your msg.
</label>
<label *ngIf="telefonos.controls[i].get('numeroCelular').errors?.required">
  your msg.
</label>

你的味精。
你的味精。
试试这个

this.formContacto = this.fb.group({
  telefonos: this.fb.array([
    [this.createNewFormGroup()],
    [Validators.required])
  ])
});
createNewFormGroup()
方法正在创建一个FormGroup,如下所示

createNewFormGroup() {
    return this.fb.group({
      tipo: [''],
      numeroCelular: ['', Validators.required],
      whatsapp: [],
      codigoCiudad: [],
      numeroFijo: [],
    })
} 
访问FormArray的验证状态

get yourName(): FormArray {
    return this.formContacto.get('telefonos') as FormArray;
} 
HTML模板

<label *ngIf="telefonos.errors?.required">
  your msg.
</label>
<label *ngIf="telefonos.controls[i].get('numeroCelular').errors?.required">
  your msg.
</label>

你的味精。
你的味精。