ImはngModelとの双方向データバインドを試みており、動作しません。 FormsModuleが含まれています。ここ コード:双方向データバインディング - 角2
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { TestComponent } from './test/test.component';
@NgModule({
declarations: [
TestComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
test.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
person = {
name: 'David',
age: '17'
};
constructor() { }
ngOnInit() {
}
}
がtest.component.html:
<form>
<input type="text" [(ngModel)]="person.name" />
<input type="text" [(ngModel)]="person.age" />
</form>
{{person.name}}<br />
{{person.age}}
それはなぜです働いていない?
ありがとうございました。
コンソールにエラーがありますか?あなたはkemskyが提案したようにあなたの入力に名前を追加する必要があります –