入门

Opt-In APIs

在我们深入了解任何表单的功能之前,我们需要使用FormsModule和/或ReactiveFormsModule引导我们的应用程序。

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { FormsModule } from '@angular/forms';
import { AppComponent } from './components'

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {
}

platformBrowserDynamic().bootstrapModule(AppModule)

Input 标签

大多数表单示例使用以下HTML5样式来标记Input:

<label for="name">Name</label>
<input type="text" name="username" id="name">

Angular 2也支持替代HTML5风格,这排除了在<input> 上的id的必要性:

<label>
  Name
  <input type="text" name="username">
</label>

results matching ""

    No results matching ""