我刚开始学角形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在这里。所以..。我需要你的帮助:)谢谢
在我阅读了您的答案并重构了我的代码之后,没关系,这是有效的!问题是我在页面联系人的模块中导入了反应性模块,我需要在我的应用程序模块中导入这个模块。因此,非常感谢您的兴趣:)
希望这个答案能帮助其他人。
发布于 2018-12-17 18:00:09
我通过在FormModule中导入shared.module并在所有其他模块中导入shared.module来解决这个问题。我的例子是在多个模块中使用FormModule。
https://stackoverflow.com/questions/43248849
复制相似问题