gpt4 book ai didi

angular - ERROR 错误 : Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[FormBuilder]

转载 作者:行者123 更新时间:2023-12-04 01:33:51 24 4
gpt4 key购买 nike

在我的 Angular 应用程序中,当我在 gift-routing.module.ts 中添加路由时,会出现此错误
当我删除它的工作路线时
但我仍然需要路由
那么我该如何解决这个错误

ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[FormBuilder]: 
StaticInjectorError(Platform: core)[FormBuilder]:
NullInjectorError: No provider for FormBuilder!
NullInjectorError: StaticInjectorError(AppModule)[FormBuilder]:
StaticInjectorError(Platform: core)[FormBuilder]:
NullInjectorError: No provider for FormBuilder!

礼物.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { GiftsRoutingModule } from './gifts-routing.module';
import { GiftListComponent } from './components/gift-list/gift-list.component';
import { GiftFormComponent } from './components/gift-form/gift-form.component';
import { SharedModule } from '../shared/shared.module';


@NgModule({
declarations: [GiftListComponent, GiftFormComponent],
imports: [
CommonModule,
GiftsRoutingModule,
SharedModule
]
})
export class GiftsModule { }

礼物路由.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LayoutComponent } from '../shared/components/layout/layout.component';
import { GiftListComponent } from './components/gift-list/gift-list.component';


const routes: Routes = [
{
path: '',
component: LayoutComponent,
children: [
{
path:'',
component: GiftListComponent
}
]
}
];


@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class GiftsRoutingModule { }

我还导入了 react 形式模块 表单模块 在我的共享模块中

shared.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { SharedRoutingModule } from './shared-routing.module';
import { LayoutComponent } from './components/layout/layout.component';
import { NavbarComponent } from './components/layout/navbar/navbar.component';

import { ReactiveFormsModule, FormsModule } from '@angular/forms'
import {
MatButtonModule,
MatCardModule,
MatInputModule,
MatIconModule,
MatTabsModule,
MatTableModule,
MatPaginatorModule,
MatSortModule,
MatProgressSpinnerModule,
MatSlideToggleModule,
MatDialogModule,
MatSelectModule,
MatDatepickerModule,
MatToolbarModule,
MatListModule,
MatMenuModule,
MatSidenavModule,
MatTooltipModule,
MatRadioModule,
MatStepperModule,
MatCheckboxModule,
MatExpansionModule,
MatProgressBarModule,
MatNativeDateModule,
} from '@angular/material';
import { RouterModule } from '@angular/router';
import { FloatingButtonComponent } from './components/floating-button/floating-button.component';
import { ConfirmComponent } from './components/confirm/confirm.component';
@NgModule({
declarations: [LayoutComponent, NavbarComponent, FloatingButtonComponent, ConfirmComponent],
imports: [
CommonModule,
SharedRoutingModule,
ReactiveFormsModule,
RouterModule,
FormsModule,
CommonModule,
MatButtonModule,
MatMenuModule,
MatSidenavModule,
MatListModule,
MatToolbarModule,
MatIconModule,
MatCardModule,
MatTabsModule,
MatInputModule,
MatTableModule,
MatPaginatorModule,
MatSortModule,
MatProgressSpinnerModule,
MatSlideToggleModule,
MatDialogModule,
MatSelectModule,
MatDatepickerModule,
MatProgressBarModule,
MatTooltipModule,
MatRadioModule,
MatStepperModule,
MatCheckboxModule,
MatExpansionModule,
MatNativeDateModule,

],
exports: [
CommonModule,
ReactiveFormsModule,
RouterModule,
FormsModule,
CommonModule,
MatButtonModule,
MatMenuModule,
MatSidenavModule,
MatListModule,
MatToolbarModule,
MatIconModule,
MatCardModule,
MatTabsModule,
MatInputModule,
MatTableModule,
MatPaginatorModule,
MatSortModule,
MatProgressSpinnerModule,
MatSlideToggleModule,
MatDialogModule,
MatSelectModule,
MatDatepickerModule,
MatProgressBarModule,
MatTooltipModule,
MatRadioModule,
MatStepperModule,
MatCheckboxModule,
MatExpansionModule,
],
entryComponents: [ConfirmComponent]
})
export class SharedModule {

}

请问我应该怎么做才能解决这个错误?

最佳答案

您需要移动导入 shared modulemain moduleFormsModuleReactiveFormsModule不作为 shared module 工作.

关于angular - ERROR 错误 : Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[FormBuilder],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60290162/

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