简体   繁体   English

无法绑定到“formGroup”,因为它不是登录组件中“form”的已知属性

[英]Can't bind to 'formGroup' since it isn't a known property of 'form' just in logincomponent

I create a form using Angular ReactiveFormsModule but I got this error message when building the app我使用 Angular ReactiveFormsModule 创建了一个表单,但在构建应用程序时收到此错误消息

ERROR in src/app/security/login/login.component.html:11:13 - error NG8002: Can't bind to 'formGroup' since it isn't a known property of 'form'. src/app/security/login/login.component.html:11:13 中的错误 - 错误 NG8002:无法绑定到“formGroup”,因为它不是“表单”的已知属性。

11 <form [formGroup]="loginForm" (ngSubmit)="loginProces()"> 11 <form [formGroup]="loginForm" (ngSubmit)="loginProces()">

for LoginComponent.对于登录组件。

I copied the same code in LogoutComponent (for testing) and no error in this component.The two components are in same module -security.我在 LogoutComponent 中复制了相同的代码(用于测试),并且该组件中没有错误。这两个组件在同一个模块 -security 中。

login.component.html: login.component.html:

 <div class="wrapper fadeInDown"> <div id="formContent"> <?-- Tabs Titles --> <!-- Icon --> <div class="fadeIn first"> <img src="" id="icon" alt="User Icon" /> </div> <!-- Login Form --> <form [formGroup]="loginForm" (ngSubmit)="loginProces()"> <input type="text" id="login" class="fadeIn second" name="login" formControlName="username" placeholder="login"> <input type="text" id="password" class="fadeIn third" name="login" formControlName="password" placeholder="password"> <input type="submit" class="fadeIn fourth" value="Log In"> </form> <!-- Remind Passowrd --> <div id="formFooter"> <a class="underlineHover" href="#">Forgot Password?</a> </div> </div> </div>

Login.component.ts登录组件.ts

 import { Component, OnInit } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { LoginService } from '../services/login.service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'] }) export class LoginComponent implements OnInit { loginForm:FormGroup; constructor(private authService: LoginService) { } ngOnInit(): void { this.initForm(); } initForm(){ this.loginForm = new FormGroup({ username: new FormControl("",[Validators.required]), password: new FormControl("",[Validators.required]) }); } loginProces(){ if(this.loginForm.valid){ this.authService.login(this.loginForm.value).subscribe(result=>{ if(result.success){ console.log(result); alert(result.message); }else{ alert(result.message); } }) } } }

Security.module.ts安全模块.ts

 import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { LoginComponent } from './login/login.component'; import { LogoutComponent } from './logout/logout.component'; import { RegisterComponent } from './register/register.component'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; @NgModule({ declarations: [ LoginComponent, LogoutComponent, RegisterComponent ], imports: [ CommonModule, FormsModule, ReactiveFormsModule, ], exports:[ ] }) export class SecurityModule { }
What am I doing wrong? 我究竟做错了什么?

Routing.module路由模块

 import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { LoginComponent } from './security/login/login.component'; const routes: Routes = [ {path:'login', component: LoginComponent } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { }

It is possible that the old bundle is still being served.可能仍在提供旧捆绑包。 The changes has to be included in the bundle which is being served.更改必须包含在提供的捆绑包中。 Restart the server and check if this problem persists.重新启动服务器并检查此问题是否仍然存在。

ng serve

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 4无法绑定到&#39;formGroup&#39;,因为它不是&#39;form&#39;的已知属性 - Angular 4 Can't bind to 'formGroup' since it isn't a known property of 'form' 无法绑定到“ formGroup”,因为它不是“ form”的已知属性。 (“角7 - Can't bind to 'formGroup' since it isn't a known property of 'form'. (" in angular 7 Angular 6:无法绑定到“formGroup”,因为它不是“form”的已知属性? - Angular 6: Can't bind to 'formGroup' since it isn't a known property of 'form'? Angular 9 - 无法绑定到“formGroup”,因为它不是“form”的已知属性 - Angular 9 - Can't bind to 'formGroup' since it isn't a known property of 'form' Angular 9 - 无法绑定到“formGroup”,因为它不是“form”的已知属性,即使正在导入 FormsModule 和 FormBuilder - Angular 9 - Can't bind to 'formGroup' since it isn't a known property of 'form' even though FormsModule and FormBuilder are being imported 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) 无法绑定到“ useStickyClasses”,因为它不是“ div”的已知属性 - Can't bind to 'useStickyClasses' since it isn't a known property of 'div' Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“matMenuTrigger”,因为它不是“a”的已知属性 - Can't bind to 'matMenuTrigger' since it isn't a known property of 'a' 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM