2016-07-18 39 views
14

我有一个角2 RC4基本形式Plunkr出现抛出下面的错误(在Chrome浏览器开发控制台)例如formGroup需要一个FormGroup例如

这里的plunkr

https://plnkr.co/edit/GtPDxw?p=preview

错误:

browser_adapter.ts:82 EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./App class App - inline template:1:7 
ORIGINAL EXCEPTION: formGroup expects a FormGroup instance. Please pass one in. 
      Example: <form [formGroup]="myFormGroup"> 

ORIGINAL STACKTRACE: 
Error: formGroup expects a FormGroup instance. Please pass one in. 
      Example: <form [formGroup]="myFormGroup"> 

    at new BaseException (https://npmcdn.com/@angular/[email protected]/src/facade/exceptions.js:27:23) 
    at FormGroupDirective._checkFormPresent (https://npmcdn.com/@angular/[email protected]/src/directives/reactive_directives/form_group_directive.js:110:19) 
    at FormGroupDirective.ngOnChanges (https://npmcdn.com/@angular/[email protected]/src/directives/reactive_directives/form_group_directive.js:39:14) 
    at DebugAppView._View_App0.detectChangesInter 

回答

24

有代码中的几个问题

  • <div [formGroup]="form">外侧的<form>标签
  • <form [formGroup]="form">的但含有FormGroup的属性的名称是loginForm因此它应该是<form [formGroup]="loginForm">
  • [formControlName]="dob"其中通过不存在的属性dob的值。你需要的是传递字符串dob[formControlName]="'dob'"或简单formControlName="dob"

Plunker example