formGroup需要一个FormGroup实例 [英] formGroup expects a FormGroup instance

查看:85
本文介绍了formGroup需要一个FormGroup实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an Angular 2 RC4 basic form example on Plunkr that appears to throw the following error (In Chrome DEV console)

这里是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/forms@0.2.0/src/facade/exceptions.js:27:23)
    at FormGroupDirective._checkFormPresent (https://npmcdn.com/@angular/forms@0.2.0/src/directives/reactive_directives/form_group_directive.js:110:19)
    at FormGroupDirective.ngOnChanges (https://npmcdn.com/@angular/forms@0.2.0/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' 或更简单的 formControlName = dob

  • <div [formGroup]="form"> outside of a <form> tag
  • <form [formGroup]="form"> but the name of the property containing the FormGroup is loginForm therefore it should be <form [formGroup]="loginForm">
  • [formControlName]="dob" which passes the value of the property dob which doesn't exist. What you need is to pass the string dob like [formControlName]="'dob'" or simpler formControlName="dob"

柱塞示例

这篇关于formGroup需要一个FormGroup实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆