无法绑定到'formGroup',因为它不是'form'的已知属性
情况:
请帮忙!我试图在我的Angular2应用程序中制作一个非常简单的表单,但无论它从不工作。
角度版本:
Angular 2.0.0 Rc5
错误:
Can't bind to 'formGroup' since it isn't a known property of 'form'
代码:
风景:
<form [formGroup]="newTaskForm" (submit)="createNewTask()"> <div class="form-group"> <label for="name">Name</label> <input type="text" name="name" required> </div> <button type="submit" class="btn btn-default">Submit</button></form>
控制器:
import { Component } from '@angular/core';import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms';import {FormsModule,ReactiveFormsModule} from '@angular/forms';import { Task } from './task';@Component({ selector: 'task-add', templateUrl: 'app/task-add.component.html'})export class TaskAddComponent { newTaskForm: FormGroup; constructor(fb: FormBuilder) { this.newTaskForm = fb.group({ name: ["", Validators.required] }); } createNewTask() { console.log(this.newTaskForm.value) }}
ngModule:
import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { FormsModule } from '@angular/forms';import { routing } from './app.routing';import { AppComponent } from './app.component';import { TaskService } from './task.service'@NgModule({ imports: [ BrowserModule, routing, FormsModule ], declarations: [ AppComponent ], providers: [ TaskService ], bootstrap: [ AppComponent ]})export class AppModule { }
问题:
为什么我会收到这个错误?
我错过了什么吗?
慕少森
素胚勾勒不出你
相关分类