我刚开始学角形2,我试着做一种反应式,但我遇到了一些麻烦。在堆栈中搜索了很多次之后,我没有找到解决方案。
在这里你可以看到我的错误

守则:
意见:
<main>
<div class="container">
<h2>User data</h2>
<form [formGroup]="userForm">
<div class="form-group">
<label>name</label>
<input type="text" class="form-control" formControlName="name">
</div>
<div class="form-group">
<label>email</label>
<input type="text" class="form-control" formControlName="email">
</div>
<div class="" formGroupName="adresse">
<div class="form-group">
<label>Rue</label>
<input type="text" class="form-control" formControlName="rue">
</div>
<div class="form-group">
<label>Ville</label>
<input type="text" class="form-control" formControlName="ville">
</div>
<div class="form-group">
<label>Cp</label>
<input type="text" class="form-control" formControlName="cp">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</main>我的module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
import { ContactComponent } from './contact.component';
import { FormGroup , FormControl , ReactiveFormsModule , FormsModule } from '@angular/forms';
@NgModule({
imports: [
NgModule,
BrowserModule,
FormsModule,
ReactiveFormsModule,
FormGroup,
FormControl
],
declarations: [
ContactComponent
]
})
export class ContactModule {}
And my component.ts
import {Component} from '@angular/core';
import { FormGroup , FormControl } from '@angular/forms';
@Component({
selector: 'contact',
templateUrl: './contact.component.html'
// styleUrls: ['../../app.component.css']
})
export class ContactComponent {
userForm = new FormGroup({
name: new FormControl(),
email: new FormControl(),
adresse: new FormGroup({
rue: new FormControl(),
ville: new FormControl(),
cp: new FormControl(),
})
});
}我不明白我的错误,因为导入ReactiveForm在这里。所以..。我需要你的帮助:)谢谢
在我阅读了您的答案并重构了我的代码之后,没关系,这是有效的!问题是我在页面联系人的模块中导入了反应性模块,我需要在我的应用程序模块中导入这个模块。因此,非常感谢您的兴趣:)
希望这个答案能帮助其他人。
发布于 2017-04-06 08:13:37
我认为这是一个旧的错误,您试图通过在模块中导入随机的东西来修复这个错误,现在代码不再编译了。虽然您没有注意shell输出,但是浏览器重新加载,仍然会得到相同的错误。
您的模块应该是:
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
ContactComponent
]
})
export class ContactModule {}发布于 2019-01-30 21:18:05
试着
<form formGroup="userForm">
而不是
<form [formGroup]="userForm">
发布于 2017-07-07 16:58:46
也尝试在组件中添加ReactiveFormsModule。
import { FormGroup, FormArray, FormBuilder,
Validators,ReactiveFormsModule } from '@angular/forms';https://stackoverflow.com/questions/43248849
复制相似问题