Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding the value in a textarea

I'm trying to do the simplest two way binding in Angular2. I would like to share a variable between my component and it's template.

My template is:

<textarea [(ngModel)]="currentQuery"></textarea>

And my component is:

import { Component } from '@angular/core';
import { ViewChild } from '@angular/core';
import { OnInit } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'vs-home',
  templateUrl: 'home.component.html'
})

export class HomeComponent {
    private currentQuery: string = '';
}

According to the docs this should work but I'm getting:

Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngModel' since it isn't a known property of 'textarea'. ("
    <div class="query-bar-container">
        <textarea [ERROR ->][(ngModel)]="currentQuery"></textarea>
        <!-- <button type="button" class="btn btn-default" (click"): HomeComponent@2:15
like image 922
Juicy Avatar asked Sep 18 '16 18:09

Juicy


People also ask

Can we use value attribute in textarea?

<textarea> does not support the value attribute.

What is value of textarea?

The value property sets or returns the contents of a text area. Note: The value of a text area is the text between the <textarea> and </textarea> tags.

What is textarea element?

The <textarea> tag defines a multi-line text input control. The <textarea> element is often used in a form, to collect user inputs like comments or reviews. A text area can hold an unlimited number of characters, and the text renders in a fixed-width font (usually Courier).

What is the input type for textarea in HTML?

input type='textarea' is not valid HTML. It partially worked because it simply defaulted to input type='text' , hence why the OP originally only saw one line.


1 Answers

@NgModule({
  ...
  imports: [
      /* BrowserModule or CommonModule */, 
      FormsModule /* or RectiveFormsModule */]
  ...
})
like image 124
Günter Zöchbauer Avatar answered Oct 16 '22 20:10

Günter Zöchbauer