我有我的主要模块-app.module.ts,它是子report.module.ts。
我在报告模块下有一些组件,在应用程序模块下有一些组件。我需要在所有这些组件中使用管道。但是,当我在App模块中导入管道时,在报告中出现错误The pipe 'moment' could not be found
。如果将管道导入添加到报表模块,则会出现类似重复声明的错误。我该怎么办?我刚接触过Angular,所以找不到解决方法。
reports.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {ReportsComponent} from './reports.component'
import { ReportsRoutingModule } from './reports-routing.module';
import { NgSelectModule } from '@ng-select/ng-select';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { MdePopoverModule } from '@material-extended/mde';
import {FilesizePipe} from '../../pipes/filesize.pipe'
// import {MomentPipe} from '../../pipes/moment.pipe'
import {AppModule} from '../../app.module'
import { ReportComponent } from './report/report.component';
import { GeneralInfoComponent } from './report/general-info/general-info.component';
import { StaticAnalysisComponent } from './report/static-analysis/static-analysis.component';
@NgModule({
declarations: [
ReportsComponent,
ReportComponent,
GeneralInfoComponent,
FilesizePipe,
// MomentPipe,
StaticAnalysisComponent
],
imports: [
CommonModule,
NgSelectModule,
MdePopoverModule,
ReportsRoutingModule,
ReactiveFormsModule,
FormsModule,
]
})
export class ReportsModule { }
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { registerLocaleData } from '@angular/common';
import localeRu from '@angular/common/locales/ru-KZ';
import localeRuExtra from '@angular/common/locales/extra/ru-KZ';
import { HeaderComponent } from './layout/header/header.component';
import { LoginComponent } from './routes/auth/login/login.component';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'
import { LoaderService } from './services';
import {LoaderInterceptor} from './interceptors/loader.service'
import 'hammerjs';
import { NgxsModule } from '@ngxs/store';
import { UploadComponent } from './routes/upload/upload.component';
import { LoaderComponent } from './layout/loader/loader.component';
import { ReportsComponent } from './routes/reports/reports.component';
import {ReportsModule} from './routes/reports/reports.module'
import {} from './routes/reports/reports.module'
import { AutofocusDirective } from './directives/autofocus.directive';
import { NotificationCenterComponent } from './layout/notification-center/notification-center.component';
import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin';
import {ReportsTableState} from './store/reportsTable.state';
import { QueueComponent } from './routes/queue/queue.component';
import { QueueTableComponent } from './routes/queue/queue-table/queue-table.component';
import { FailedAnalysesComponent } from './routes/queue/failed-analyses/failed-analyses.component';
import { MomentPipe } from './pipes/moment.pipe';
// import { FilesizePipe } from './pipes/filesize.pipe';
registerLocaleData(localeRu, 'ru', localeRuExtra);
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
LoginComponent,
UploadComponent,
LoaderComponent,
// ReportsComponent,
AutofocusDirective,
NotificationCenterComponent,
QueueComponent,
QueueTableComponent,
FailedAnalysesComponent,
MomentPipe,
// FilesizePipe,
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
ReactiveFormsModule,
FormsModule,
HttpClientModule,
NgxsLoggerPluginModule.forRoot(),
NgxsModule.forRoot([
ReportsTableState
], {developmentMode:true})
],
providers: [
LoaderService,
{ provide: HTTP_INTERCEPTORS, useClass: LoaderInterceptor, multi: true },
],
bootstrap: [AppComponent]
})
export class AppModule { }
答案 0 :(得分:2)
您应该有3个模块,您的管道位于第三个模块中。
@NgModule({
declaration: [MomentPipe],
exports: [MomentPipe],
})
export class PipesModule {}
通过导出第三个模块中的管道,可以在导入该第三模块的任何位置使它们可用。
答案 1 :(得分:0)
将管道添加到单独的模块,然后将该模块导入AppModule和ReportsModule。