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
1.1k views
in Technique[技术] by (71.8m points)

angular - mat-checkbox that display the error TypeError: this.form._updateTreeValidity is not a function

I work on an angular application. In a component, I have the following code

export class GlobalComponent {
  @Input()
  form!: FormGroup<DeepRequired<GlobalBean>>

with the following template extract

..................
<mode-impression-ticket [form]="form" [labelCheckBox]="text" ></mode-impression-ticket>
...................

Here is the following mode-impression-ticket component

@Component({
  selector: "mode-impression-ticket",
.............
export class LocalComponent implements OnInit {

  @Input()
  form!: FormGroup<DeepRequired<GlobalBean>>

  localForm: FormGroup<DeepRequired<GlobalBean>> | undefined;



@Input()
  labelCheckBox!: string

  ngOnInit() {
    this.localForm = Object.assign({}, this.form);
    console.log(this.localForm);
    console.log(this.localForm.controls['flag']?.value);
    console.log(this.labelCheckBox);

The objective of the preceeding component is to get the values of fields with the same form and afterwards forward it to its parent The console.log above don't give any error and print value

With the following template extract

@Component({
  selector: "mode-impression-ticket",
  template: `
    <form [formGroup]="localForm">
    <mat-checkbox  formControlName="flag">{{labelCheckBox}}</mat-checkbox>
.........................................

And there is an error at line <mat-checkbox formControlName.........

TypeError: this.form._updateTreeValidity is not a function

UPDATE

this.form is initialized in two component above (grand parent component in a method which is the following underneath). The child, parent and grand parent component have the same form

  ngOnInit() {
    this.form = VtForm.build(this._route,
      FormHelpers.getInitData(this._route),
    )
  }
question from:https://stackoverflow.com/questions/65943222/mat-checkbox-that-display-the-error-typeerror-this-form-updatetreevalidity-is

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

1 Reply

0 votes
by (71.8m points)

I forgot also to tell you that I use @ng-stack/forms

Finally I use the same form as parent and don't duplicate it

export class LocalComponent {


  @Input()
  formGroup!: FormGroup<Required<VtParamTermIhmBean>>

Furthermore, I changed the template (see the following post: reactiveform that does not compile) and everything was put in order. The discussion is closed. Thank you


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

...