gpt4 book ai didi

Angular 6 : Can't bind to 'FormGroup' since it isn't a known property of 'form'

转载 作者:行者123 更新时间:2023-12-02 00:30:00 28 4
gpt4 key购买 nike

我是 Angular 6 的新手,正在研究 ReactiveForms。收到此错误且无法编译。我已经看到了不同的解决方案,并按照解决方案中的建议在 Imports 中添加了 ReactiveFormsModule 指令,但它仍然显示相同的错误。请帮忙。

与您分享所需的错误代码和屏幕截图。app.module.ts

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { SignupFormComponent } from './signup-form/signup-form.component';
import { AuthorsService } from './authors.service';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

@NgModule({
declarations: [
AppComponent,
SignupFormComponent,
CoursesComponent,
CourseComponent,
AuthorsComponent,
FavoriteComponent,
TitleCasePipe,
PanelComponent,
LikeComponent,
ZippyComponent,
ContactFormComponent,
NewCourseFormComponent
],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule
],

注册表单.ts

import { FormGroup, FormControl, ReactiveFormsModule } from '@angular/forms';
import { Component } from '@angular/core';

@Component({
selector: 'signup-form',
templateUrl: './signup-form.component.html',
styleUrls: ['./signup-form.component.css']
})
export class SignupFormComponent {
form = new FormGroup({
username: new FormControl(),
password: new FormControl()
});

}

signup-form.html

<form [FormGroup]="form">
<div class="form-group">
<label for="username">Username</label>
<input
formControlName="username"
id="username"
type="text"
class="form-control">
</div>
<div class="form-group">
<label for="password">Password</label>
<input
formControlName="password"
id="password"
type="text"
class="form-control">
</div>
<button class="btn btn-primary" type="submit">Sign Up</button>
</form>

Error Screenshot

最佳答案

请使用下面的 HTML

<form [formGroup]="form">
...
</form>

错误就在那里,因为你在 [formGroup] 中使用了大写字母 F。

关于 Angular 6 : Can't bind to 'FormGroup' since it isn't a known property of 'form' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52253567/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com