【问题标题】:Cannot declaremodule in an NgModule as it's not a part of the current compilation Angular不能在 NgModule 中声明模块,因为它不是当前编译 Angular 的一部分
【发布时间】:2020-09-09 17:14:44
【问题描述】:

我不确定这里发生了什么,但我在将“formsModule”和“reactiveformsmodule”导入我的 app.module 组件时收到此错误“无法在 NgModule 中声明“FormsModule”,因为它不是当前编译的一部分” .

我正在运行 Angular 9 并尝试清除缓存,重新安装 npm。这些可能是角度 9 问题吗?会降级到 8 解决问题...

我对这里发生的事情感到困惑,因为它在前一天正常导入。

app.module.ts

    import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { ExpertAdviceLandingPageComponent } from './expert-advice-landing-page/expert-advice-landing-page.component';
import { InstagramComponent } from './instagram/instagram.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { SharedModule } from './shared/shared.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { BuyingGuideComponent } from './buying-guide/buying-guide.component';
import { IdeasAndInspirationComponent } from './ideas-and-inspiration/ideas-and-inspiration.component';
import { AdviceAndGuidanceComponent } from './advice-and-guidance/advice-and-guidance.component';
import { GuidesComponent } from './guides/guides.component';
import { CommonModule } from '@angular/common';
import { CarouselComponent } from './carousel/carousel.component';
import { CarouselModule } from 'angular-bootstrap-md';
import { AppRoutingModule } from './app-routing.module';
import { SharedService } from './shared/sharedService';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
  declarations: [
    AppComponent,
    BuyingGuideComponent,
    IdeasAndInspirationComponent,
    AdviceAndGuidanceComponent,
    GuidesComponent,
    ExpertAdviceLandingPageComponent,
    InstagramComponent,
    CarouselComponent,
    FormsModule,
    ReactiveFormsModule
  ],
  imports: [
    BrowserModule,
    SharedModule,
    HttpClientModule,
    CommonModule,
    CarouselModule,
    MDBBootstrapModule.forRoot(),
    BrowserAnimationsModule,
    AppRoutingModule,
    NgbModule,
    FormsModule,
    ReactiveFormsModule

  ],
  providers: [SharedService],
  bootstrap: [AppComponent]
})
export class AppModule {
}

【问题讨论】:

  • 考虑从声明数组中删除FormsModule, and ReactiveFormsModule
  • 天哪,我从来没有注意到这一点!谢谢

标签: javascript html angular angular9


【解决方案1】:

在 Angular 中导入模块时,它应该放在 imports 数组而不是 declarations 下。

declarations: [
    AppComponent,
    // ReactiveFormsModule---remove from declarations and add in import because its is imported
    // FormsModule`enter code here`---remove from declarations and add in import
],
imports: [
    ReactiveFormsModule,
    FormsModule
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-21
    • 2018-01-27
    • 2019-12-20
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    相关资源
    最近更新 更多