xRay
xRay

Reputation: 801

Not able to display the value within the input field

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.

Upvotes: 0

Views: 63

Answers (2)

Adrii
Adrii

Reputation: 1740

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],
});

Upvotes: 1

manjiro sano
manjiro sano

Reputation: 842

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.

Upvotes: 1

Related Questions