首页 > 解决方案 > Angular 4 - 无法绑定到“ngmodel”,因为它不是“输入”的已知属性。("

问题描述

下面是代码片段,即使在导入 Formmodule 后我也遇到了错误,它没有解决

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {AppComponent} from './app.component';
import{firstComponent} from './first/first.component';

import { SecondComponent } from './second/second.component';


@NgModule({
  declarations: [
    AppComponent,
    firstComponent,
    SecondComponent
  ],
  imports: [
      BrowserModule,
      FormsModule
  ],

Sec.component.html
==================

<input type="text" [(ngmodel)]="TwoWayData" [value]="TwoWayData" name=""  >
{{TwoWayData}}

Sec.component.ts

TwoWayData:string='Fortune';

标签: angular

解决方案


你的问题在这里,在 [(ngmodel)] M 是大写

[(ngmodel)]="TwoWayData"

代替它

<input type="text" [(ngModel)]="TwoWayData" [value]="TwoWayData" name="">

{{TwoWayData}}


推荐阅读