Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
New Input does not change FormGroup disable property on Sub Component

I have two components Parent and Child.

Parent stores the state of the formGroup used in the child component. Each time I receive new data from external source, I pass this data through template and construct new FormGroup and decide based on one property if FormGroup is enabled or disabled. New data are changed as I want but the disabled/enabled state does not.

My code:

Child component

@Input() edvForm: FormGroup;
@Input() isBlocMainSupport: boolean;
@Input() data: Data;

ngOnChanges(changes: SimpleChanges): void {
   this.setForm();
}

setForm() {
   ...
   this.edvForm.addControl(
      'supportType',
      new FormControl({ value: supportType, disabled: !this.isBlocMainSupport })
   );
}

Parent component

edvForm: FormGroup;
isBlocMainSupport = true;
data: Data;

...

ngOnInit(): void {
   this.sourceEvent$
      .pipe(takeUntil(this.destroy$))
      .subscribe(newData => {
        this.newGraphicElements([newData]);
      });
}

...

newGraphicElements(newData: Data[]) {

   this.reset();
   ...
   this.data = newData[0];
   this.isBlocMainSupport = myCondition ? true : false;
}

...

reset() {
   this.edvForm = new FormGroup({});
}

Parent template

<child-comp
   *ngIf="isTheRightChild"
   [data]="data"
   [edvForm]="edvForm"
   [isBlocMainSupport]="isBlocMainSupport"
></child-comp>

To resume, data are well passed and change everytime as needed. But, disable state is not applied with : "disabled: !this.isBlocMainSupport"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I found the solution on github: formGroup disable()/enable() does not work right after init #22556

The problem is the change detector. The following code is working :

this.changeDetector.detectChanges(); // use it before using disable/enable
this.form.controls['name'].disable();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda