今天发生了一个非常奇怪的错误:
未捕获的错误:类型DashboardComponent是以下内容的声明的一部分 2个模块:DashboardModule和DashboardModule!
对我来说这没有任何意义。只有一个名为DashboardModule的模块,并且DashboardComponent在此模块中仅声明和导出一次。
*更新
这是DashboardModule的外观
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { FormsModule } from "@angular/forms";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { TranslateModule } from "@ngx-translate/core";
import { TypeaheadModule } from "root/shared/typeahead/typeahead.module";
import { AppFormsModule } from "root/shared/forms/forms.module";
import { DynamicComponentService } from "./dynamicComponent.service";
import { DashboardComponent } from "./dashboard.component";
import { DashboardWidgetComponent } from "./widget.component";
import { ModalConfigComponent } from "./modalConfig.component";
import { DashboardService } from "./dashboard.service";
@NgModule({
imports: [
CommonModule,
FormsModule,
NgbModule,
TranslateModule,
TypeaheadModule,
AppFormsModule],
exports: [
DashboardComponent,
DashboardWidgetComponent,
ModalConfigComponent],
declarations: [
DashboardComponent,
DashboardWidgetComponent,
ModalConfigComponent],
providers: [
DynamicComponentService,
DashboardService],
entryComponents: [
ModalConfigComponent]
})
export class DashboardModule { }
答案 0 :(得分:1)
与此同时,我发现了该错误:
Visual Studio代码决定以新样式导入DashobardModule。代替
import { DashboardModule } from "root/shared/dashboard/dashboard.module";
它开始生成此代码
import { DashboardModule } from "root/shared/dashboard/dashboard.module.js";
在代码的其他部分,旧方法仍然存在。因此,有角度的想法将存在两个不同的DashboardModules并提出上面的错误。事实证明Angular的行为完全正确,但是我必须找出为什么VS Code开始产生如此可怕的混乱……