VSTR
VSTR

Reputation: 23

How to set value for textarea in angular 7

I use angular 7 form in following way. When I try to use patchValue for textarea element it doesnt set any value.

  mainBlockIdeaForm = new FormGroup({
    title: new FormControl('', [Validators.required]),
    caption: new FormControl('', [Validators.required]),
    description: new FormControl('', [Validators.required])
  });
<form [formGroup]="mainBlockIdeaForm">

<div class="form-group input-group">
            <input class="form-control" placeholder="caption" formControlName="caption"/>
          </div>

          <div class="form-group input-group">
            <input class="form-control" placeholder="title" formControlName="title"/>
          </div>
          <div class="form-group input-group">
            <textarea class="form-text-control" placeholder="description"  formControlName="description"></textarea>
          </div>
        </form>
    this.mainBlockIdeaForm.patchValue({
      caption: this.idea.caption,
      title: this.idea.title,
      description: this.idea.description});

Upvotes: 1

Views: 14511

Answers (4)

Akash Singh
Akash Singh

Reputation: 11

<textarea style="background-color:black;color:white;" [(ngModel)]='someValue' rows="30" cols="120">                             

the NgModel Will help Your Demand . and if You want it through form Control then use the code

or

description: new FormControl(data ?data : null ,{}), in html

or using Form Controls

this.mainBlockIdeaForm.controls.description.setValue("Required value");

live Example https://stackblitz.com/edit/angular-6-reactive-forms-4ssfml

Upvotes: 1

Sourav Golui
Sourav Golui

Reputation: 633

You can do like this :)

 this.mainBlockIdeaForm.patchValue({description: 'SG'});

Upvotes: 2

JStw
JStw

Reputation: 1205

I don't know how you actually update your form control, but basically you can do something like :

this.mainBlockIdeaForm.get('description').setValue('your value');

And your textarea will be updated.

Upvotes: 3

Ling Vu
Ling Vu

Reputation: 5181

Try

this.mainBlockIdeaForm.controls.description.setValue(this.idea.description);

Upvotes: 0

Related Questions