Home > OS >  Not able to display the value within the input field
Not able to display the value within the input field

Time:05-21

I have an input field and I would like to place a default value. This is how I tried it:

<input matInput formControlName="name" value="Ray">

The value is not getting displayed. See my code on StackBlitz.

CodePudding user response:

Your input is bind to a FormControl, so just set "Ray" value in your "name" form control and remove value="Ray" in your template :

<input matInput formControlName="name">


formMain = this._fb.group({
   name: ['Ray', Validators.required],
});

CodePudding user response:

On DialogOverviewExample, the formControl must have a value. If you put it like this:

  formMain = this._fb.group({
    name: ['myName', Validators.required],
  });

"myName" will be displayed on the input.

  • Related