我正在创建一个注册表单,我收到表单组不是已知属性的错误。我还有其他反应形式,它们都可以工作,但只有这个。我在 app 模块和所有内容中添加了所有导入。想知道是不是因为 app/core/auth 中的注册页面。
compiler.js:1021 Uncaught Error: Template parse errors:
Can't bind to 'formGroup' since it isn't a known property of 'form'. ("<div class="container" style="margin-top: 40px;">
<form [ERROR ->][formGroup]="registrationForm">
app.module.ts
imports: [
FormsModule,
ReactiveFormsModule
],
注册组件.ts
import { RegistrationModel } from './../../../shared/models/registration.model';
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
import {FormBuilder, FormGroup, ReactiveFormsModule} from '@angular/forms';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
registrationForm: FormGroup;
private registrationModel: RegistrationModel;
constructor(private fb: FormBuilder) {
this.registrationModel = new RegistrationModel;
}
ngOnInit() {
this.registrationForm = this.fb.group({
'first_name': [''],
'middle_name': [''],
'last_name': [''],
'date_of_birth': [''],
});
this.registrationForm.valueChanges.subscribe(newVal => console.log(newVal));
}
onSubmit() {
console.log(this.registrationForm);
}
}
注册html
<div class="container" style="margin-top: 40px;">
<form [formGroup]="registrationForm">
<div class="row">
<div class="col-md-12">
<h3 class="text-center">Register Account</h3>
<hr>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label>First Name</label>
<input type="text" class="form-control">
</div>
<div class="form-group col-md-6">
<label>Middle Name</label>
<input type="text" class="form-control">
</div>
</div>