Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
525 views
in Technique[技术] by (71.8m points)

angular - Why when I disable parent FormGroup multiple times child FormGroup is not disabled too?

Why when I disable parent FormGroup multiple times child FormGroup is not disabled too?

ts code:

import { FormGroup, FormControl } from "@angular/forms";
import { OnInit } from "@angular/core";

export class AppEditComponent implements OnInit {
  form = new FormGroup({
    parent: new FormGroup({
      child: new FormGroup({
        control: new FormControl("text"),
      }),
    }),
  });

  constructor() {}

  ngOnInit(): void {
    this.form.get('parent').disable();
  }

  toggle() {
    const control = this.form.get('parent);
    control.enabled ? control.disable() : control.enable();
  }
}

html code:

<button (click)="toggle()"></button>
<pre>{{ form.value | json }}</pre>

html result:

{
  "parent": {
    "child": {
      "control": "text",
    },
  },
}

I want when I disable the parent formGroup so disable child formGorup too, because I have multiple sub-formGroup per parent formGroup with many controlGroup per formGroup.

Any idea how can I disable all child formGroup when I disable the parent formGroup?

Thanks.

question from:https://stackoverflow.com/questions/65900594/why-when-i-disable-parent-formgroup-multiple-times-child-formgroup-is-not-disabl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...