Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!