Binding the value in a textarea

爱⌒轻易说出口 提交于 2019-12-12 08:21:07

问题


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

回答1:


@NgModule({
  ...
  imports: [
      /* BrowserModule or CommonModule */, 
      FormsModule /* or RectiveFormsModule */]
  ...
})


来源:https://stackoverflow.com/questions/39561181/binding-the-value-in-a-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!