无法绑定到“ formGroup”,因为它不是“ form” angular 8的已知属性

时间:2020-05-01 16:13:42

标签: angular ionic-framework

我在控制台中遇到此错误

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

,并且我已经在app.module.ts中添加了FormsModule,ReactiveFormsModule模块,并且错误仍然存​​在

我已经重新启动了服务器,它仍然是一样的,有人可以指导我,谢谢 我已经重新启动了服务器,它仍然是一样的,有人可以指导我,谢谢

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

component.ts

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { CustomValidators } from "ng2-validation";

@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
  valForm: FormGroup;
  constructor(public fb: FormBuilder) {
    this.valForm = fb.group({
      email: [
        "ionicfirebaseapp@gmail.com",
        Validators.compose([Validators.required, CustomValidators.email])
      ],
      password: ["123456", Validators.required]
    });

   }

  ngOnInit() {
  }

}

app.module.ts

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

    import { CommonModule }  from '@angular/common';

    import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
    import { SplashScreen } from '@ionic-native/splash-screen/ngx';
    import { StatusBar } from '@ionic-native/status-bar/ngx';

    import { AppComponent } from './app.component';
    import { AppRoutingModule } from './app-routing.module';
    import { HttpClientModule } from '@angular/common/http'



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

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


      ],
      providers: [
        StatusBar,
        SplashScreen,

        { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
      ],
      bootstrap: [AppComponent]
    })
    export class AppModule {}

app-routing.module.ts

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { AuthGuard } from './_guard/auth.guard';

const routes: Routes = [
  {
    path: '',
    redirectTo: 'home',
    pathMatch: 'full'
  },
  {
    path: 'folder/:id',
    canActivate: [AuthGuard],
    loadChildren: () => import('./folder/folder.module').then( m => m.FolderPageModule)
  },
  {
    path: 'home',
    canActivate: [AuthGuard],
    loadChildren: () => import('./pages/home/home.module').then( m => m.HomePageModule)
  },
  {
    path: 'product-list/:id',
    canActivate: [AuthGuard],
    loadChildren: () => import('./pages/product-list/product-list.module').then( m => m.ProductListPageModule)
  },
  {
    path: 'product-details',
    canActivate: [AuthGuard],
    loadChildren: () => import('./pages/product-details/product-details.module').then( m => m.ProductDetailsPageModule)
  },
  {
    path: 'cart',
    canActivate: [AuthGuard],
    loadChildren: () => import('./pages/cart/cart.module').then( m => m.CartPageModule)
  },
  {
    path: 'categories',
    canActivate: [AuthGuard],
    loadChildren: () => import('./pages/categories/categories.module' ).then( m => m.CategoriesPageModule)
  },
  {
    path: 'login',
    loadChildren: () => import('./pages/login/login.module').then( m => m.LoginPageModule)
  },
  {
    path: 'register',
    loadChildren: () => import('./pages/register/register.module').then( m => m.RegisterPageModule)
  }
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule {}

0 个答案:

没有答案