angular 2错误:Can't resolve for FormGroup的所有参数
angular 2 error: Can't resolve all parameters for FormGroup
我遵循thoughttram的教程FormBuilder http://blog.thoughtram.io/angular/2016/06/22/model-driven-forms-in-angular-2.html我复制了代码并更改了一些变量名称。我使用的是Angular 2.1.2、Typescript 2.0.8和Angular Material2(来自Google)。Atom Typescript说任何页面上都没有错误。尽管如此,我还是在加载时出现错误,并且页面没有使用这段新代码加载。
zone.js:388 Unhandled Promise rejection: Can't resolve all parameters for FormGroup: (?, ?, ?). ; Zone: <root> ; Task: Promise.then ; Value: Error: Can't resolve all parameters for FormGroup: (?, ?, ?).(…) Error: Can't resolve all parameters for FormGroup: (?, ?, ?).
at CompileMetadataResolver.getDependenciesMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14598:21)
at CompileMetadataResolver.getTypeMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14499:28)
at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14642:43)
at Array.forEach (native)
at CompileMetadataResolver.getProvidersMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14622:21)
at CompileMetadataResolver.getDirectiveMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14262:36)
at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14367:51)
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14361:51)
at RuntimeCompiler._compileComponents (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17063:49)consoleError @ zone.js:388_loop_1 @ zone.js:417drainMicroTaskQueue @ zone.js:421ZoneTask.invoke @ zone.js:339
2016-11-10 16:01:40.394 zone.js:390 Error: Uncaught (in promise): Error: Can't resolve all parameters for FormGroup: (?, ?, ?).(…)consoleError @ zone.js:390_loop_1 @ zone.js:417drainMicroTaskQueue @ zone.js:421ZoneTask.invoke @ zone.js:339
HTML示例 for apartment4Rent.component.html
<form [formGroup]="registerApartment4RentForm" (submit)="onSubmit($event)">
<md-input id="country" name="country" class="required" aria-labelledby="country" formControlName="country"
i18n-placeholder="select country placeholder" placeholder="Country" type="text" size="30" maxlength="30">
</md-input>
加上4,州,城市,街道和邮政编码相同
AppComponent with constructor from the tutorial - in the app folder
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';
@Component({
moduleId: module.id,
selector: 'residence-app',
templateUrl: "components/navigation/headerFooter.html",
styleUrls: [ "components/navigation/styleHeaderFooter.css" ],
providers: [
FormBuilder,
FormGroup
]
})
export class AppComponent implements OnInit {
registerApartment4RentForm: FormGroup;
constructor(private formBuilder: FormBuilder) {}
ngOnInit() {
this.registerApartment4RentForm = this.formBuilder.group({
country: '',
stateProvince: '',
address: this.formBuilder.group({
streetAddress: '',
zipCode: '',
city: ''
})
});
}
}
templateUrl中的headerFooter.html有一些用于页眉和页脚的html和
<div>
<router-outlet></router-outlet>
</div>
在我尝试这个响应式表单代码之前,在其中加载和显示公寓4rent .component.html。目录结构是app/components/input/apartment4Rent.component(s)
响应式表单需要做哪些改变?
你把Angular响应式表单模块作为导入添加到你的模块了吗?看起来它缺少由该模块注册的服务。
(我在打电话,很抱歉简短的回答)
编辑
我的意思是:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@anglar/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [BrowserModule, ReactiveFormsModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
注意ReactiveFormsModule
出现此错误的另一个原因是您导入了两次formgroup。我在我的应用程序模块中删除了它,现在它为我工作,希望它能帮助别人。
- 为什么JavaScript在for循环为3时向所有4发出警报
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- Is onfling available for html, html5
- Setting default onclick behavior for <img> tag in gene
- 我的javascript for循环不起作用
- For循环冻结Javascript
- 如何在for循环中添加事件侦听器
- Javascript setTimeout for an array
- 双“for”循环(循环)
- 引用vue.js中v-for中的上一个值
- javascript for循环不起作用
- for循环中的javascript if语句找不到==
- GWT (or javascript) library for couchDB
- Javascript在for循环中等待处理请求
- Livereload for node.js.有可能吗
- jQuery setTimeOut: in for-loop
- 我没有'I don’我不理解for在循环中的用途
- 如何知道javascript for语句中的所有结果是否都是错误的
- For循环在Jquery中只运行一次
- angular 2错误:Can't resolve for FormGroup的所有参数