我在Plunkr上有一个Angular 2 RC4基本表单示例,似乎引发了以下错误(在Chrome DEV控制台中)

这是小矮人

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

最佳答案

您的代码中有一些问题

  • 标记之外的
  • <div [formGroup]="form">
  • <form>,但包含<form [formGroup]="form">的属性的名称为FormGroup,因此应为loginForm
  • <form [formGroup]="loginForm">传递不存在的属性[formControlName]="dob"的值。您需要的是传递字符串dob,例如dob或更简单的[formControlName]="'dob'"

  • Plunker example

    关于angular - formGroup需要一个FormGroup实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38444778/

    10-11 10:32