我在运行 Angular 2 的最终发布版本时遇到了 ngModule 和我的组件的配置问题。
这就是我所拥有的:
//PageHeaderModule
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PageHeaderComponent } from './index';
@NgModule({
imports: [CommonModule],
declarations: [PageHeaderComponent]
})
export class PageHeaderModule { }
//Shared Module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { HeaderComponent, SideBarComponent, BurgerMenuComponent, FooterComponent, InnerSpinnerComponent, PageHeaderComponent } from "./components/index";
import { UniqueNameValidationByList } from "./directives/index";
import { LowerCasePipe, WhitespacePipe } from "./pipes/index";
@NgModule({
imports: [CommonModule, RouterModule],
declarations: [
PageHeaderComponent,
HeaderComponent,
SideBarComponent,
BurgerMenuComponent,
FooterComponent,
InnerSpinnerComponent,
UniqueNameValidationByList,
LowerCasePipe, WhitespacePipe
],
exports: [
PageHeaderComponent,
HeaderComponent,
SideBarComponent,
BurgerMenuComponent,
FooterComponent,
InnerSpinnerComponent,
UniqueNameValidationByList,
LowerCasePipe, WhitespacePipe
],
})
export class SharedModule { }
//AppModule
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Routes, RouterModule } from '@angular/router';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { routing, appRoutes } from './app.routes';
import { AppComponent } from './app.component';
import { BillingModule } from './billing/billing.module';
import { CustomersModule } from './customers/customers.module';
import { DashboardModule } from './dashboard/dashboard.module';
import { DevicesModule } from './devices/devices.module';
import { GroupsModule } from './groups/groups.module';
import { ProductsModule } from './products/products.module';
import { ReportingModule } from './reporting/reporting.module';
import { LoginModule } from './login/login.module';
import { SharedModule } from "./shared/shared.module";
import { SideBarService } from "./shared/components/index";
import { SignalRService, CountriesService } from "./shared/services/index";
@NgModule({
imports: [BrowserModule,
RouterModule.forRoot(appRoutes, { useHash: true }),
routing,
SharedModule,
BillingModule,
CustomersModule,
DashboardModule,
DevicesModule,
GroupsModule,
ProductsModule,
ReportingModule,
LoginModule
],
declarations: [AppComponent],
providers: [{ provide: LocationStrategy, useClass: HashLocationStrategy },
SideBarService,
SignalRService,
CountriesService],
bootstrap: [AppComponent],
})
export class AppModule { }
注意这里的两件事:
1)我没有使用页眉模块,因为我认为 sharedModule 应该照顾所有这些共享组件,而是一个一个地创建,但我不确定。
2)我只是在共享模块中使用“导出”,而不是在我的应用程序中的任何其他模块中
我得到的错误是这个:
我一直在尝试很多事情,但似乎没有什么能解决我的问题,我非常感谢你能提供的任何帮助。
如果需要更多信息,请告诉我。
谢谢