绑定文本区域中的值

2024-01-24

我正在尝试在 Angular2 中进行最简单的两种方式绑定。我想在我的组件和它的模板之间共享一个变量。

我的模板是:

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

我的组件是:

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 = '';
}

根据文档,这应该有效,但我得到:

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

@NgModule({
  ...
  imports: [
      /* BrowserModule or CommonModule */, 
      FormsModule /* or RectiveFormsModule */]
  ...
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

绑定文本区域中的值 的相关文章

随机推荐