当前位置: 首页 > 知识库问答 >
问题:

无法绑定到“formGroup ”,因为它不是ionic [duplicate]中“form”的已知属性

祁均
2023-03-14

我尝试使用Ionic(angular framework)进行简单登录,但我遇到了这个错误,我不知道如何解决它

   Can't bind to 'formGroup' since it isn't a known property of 'form'

我搜索了所有人,当他们添加< code >反应式模块时,错误消失了,但当我添加时,错误仍然存在

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Akaya+Telivigala&display=swap" rel="stylesheet">

<ion-header [translucent]="true" class="ion-no-border">
  <ion-toolbar>
    <div class="black-circle"></div>
    <ion-title class="ion-text-center custom-font">Se Connecter</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
  <svg class="back-bolb" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
    <path fill="#CCCCCC" d="M65,-20C70,-5.6,50.1,18,26.8,34.3C3.5,50.7,-23.3,59.7,-41.2,48.6C-59.1,37.5,-68.2,6.2,-59.9,-12.8C-51.5,-31.7,-25.8,-38.3,2.1,-39C30,-39.7,59.9,-34.4,65,-20Z" transform="translate(100 100)" />
  </svg>

  <div class="ion-padding">

    <form class="ion-no-padding" [formGroup]="todo" (ngSubmit)="logForm()">
       <div class="wrap-input">
         <input class="input" type="text"  placeholder="Numero de matricule">
       </div>
       <div class="wrap-input">
        <input class="input" type="password"  placeholder="Le Mot de passe">
       </div>
       <div class ="container-form-btn">
        <button class="form-btn custom-font">
          Soumettre
        </button>
       </div>
    </form>

  </div>
</ion-content>

the app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

import { CommonModule } from '@angular/common';
import {FormsModule,ReactiveFormsModule} from '@angular/forms';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule,FormsModule,ReactiveFormsModule, IonicModule.forRoot(), AppRoutingModule],

providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
  bootstrap: [AppComponent],
  exports: [FormsModule,ReactiveFormsModule,CommonModule]
})
export class AppModule {}

控制器1.ts

import { Component } from '@angular/core';
import {Validators, FormBuilder, FormGroup } from '@angular/forms';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
   todo : FormGroup;
  constructor(private formBuilder: FormBuilder) {
    this.todo = this.formBuilder.group({
      employeeN: ['', Validators.required],
      password: [''],
    });
  }

  logForm(){
    console.log(this.todo.value)
  }

}

我错过了什么吗?请帮助我,我正在处理这个错误

共有1个答案

江洲
2023-03-14

如果主页有自己的模块,您需要在那里进行导入,否则您需要将主页组件添加到应用程序模块的声明中。

这实际上是与Angular 9重复的问题-无法绑定到“formGroup ”,因为它不是“form”的已知属性

 类似资料: