Home > database >  reactive forms angular form group
reactive forms angular form group

Time:01-21

Why I can't write into the input before the set value?

html

<form action="" [formGroup]="titleForm">
    <input  type="text" formControlName="title">
</form>

typescript

  titleForm : FormGroup = new FormGroup(
    {'title':new FormControl}
  );

    this.titleForm.patchValue({
      title:"hello"
    });
  }

the input value is successfully changed but I can't write into the input

CodePudding user response:

rewrite formGroup to this

  titleForm : FormGroup = new FormGroup({
      title: new FormControl('')
  });
  •  Tags:  
  • Related