为什么可以';我的Angular2 rc5组件找不到我的共享管道?
我正在将一个项目更新为rc5,并从创建一个主模块开始,该模块加载整个应用程序的所有指令、管道等。我把它拿起来运行,一切都很好。我现在正试图将主模块拆分为更小的模块,这对我的应用程序的结构和使用都有意义。我希望我的应用程序有一个模块,只存储多个组件共享的所有管道,因此我制作了这个模块: pipes.module.ts为什么可以';我的Angular2 rc5组件找不到我的共享管道?,angular,typescript,module,pipe,Angular,Typescript,Module,Pipe,我正在将一个项目更新为rc5,并从创建一个主模块开始,该模块加载整个应用程序的所有指令、管道等。我把它拿起来运行,一切都很好。我现在正试图将主模块拆分为更小的模块,这对我的应用程序的结构和使用都有意义。我希望我的应用程序有一个模块,只存储多个组件共享的所有管道,因此我制作了这个模块: pipes.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, provideForms } from '@angular/forms';
import { AbbrDay } from './abbr-day.pipe'
import { TitleCase } from './title-case.pipe'
import { ToDate } from './to-date.pipe'
@NgModule({
declarations: [
AbbrDay,
TitleCase,
ToDate
],
imports: [
BrowserModule,
FormsModule
],
providers: [
provideForms
]
})
export class PipesModule {
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, provideForms } from '@angular/forms';
import { MODAL_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
import { Schedule } from 'primeng/primeng';
import {
AppointmentConfirmComponent,
AppointmentDetailComponent,
CalendarBodyComponent,
CalendarComponent,
CalendarService
} from './'
import { PipesModule } from '../../shared/pipes/pipes.module'
import { SearchIdentitiesComponent } from '../identity'
@NgModule({
declarations: [
AppointmentConfirmComponent,
AppointmentDetailComponent,
CalendarBodyComponent,
CalendarComponent,
MODAL_DIRECTIVES,
Schedule,
SearchIdentitiesComponent
],
imports: [
BrowserModule,
FormsModule,
PipesModule
],
providers: [
provideForms
]
})
export class CalendarModule {
}
在另一个模块中,我想使用TitleCase管道,因此我尝试导入管道模块:
calendar.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, provideForms } from '@angular/forms';
import { AbbrDay } from './abbr-day.pipe'
import { TitleCase } from './title-case.pipe'
import { ToDate } from './to-date.pipe'
@NgModule({
declarations: [
AbbrDay,
TitleCase,
ToDate
],
imports: [
BrowserModule,
FormsModule
],
providers: [
provideForms
]
})
export class PipesModule {
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, provideForms } from '@angular/forms';
import { MODAL_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
import { Schedule } from 'primeng/primeng';
import {
AppointmentConfirmComponent,
AppointmentDetailComponent,
CalendarBodyComponent,
CalendarComponent,
CalendarService
} from './'
import { PipesModule } from '../../shared/pipes/pipes.module'
import { SearchIdentitiesComponent } from '../identity'
@NgModule({
declarations: [
AppointmentConfirmComponent,
AppointmentDetailComponent,
CalendarBodyComponent,
CalendarComponent,
MODAL_DIRECTIVES,
Schedule,
SearchIdentitiesComponent
],
imports: [
BrowserModule,
FormsModule,
PipesModule
],
providers: [
provideForms
]
})
export class CalendarModule {
}
运行应用程序时,在运行时出现以下错误:
zone.js:478 Unhandled Promise rejection: Template parse errors:
The pipe 'titleCase' could not be found ("ties"
class="tag black-text pointer" [ngClass]="{'strike': participantsDiff()}">[ERROR ->]
{{identityHelperService.getName(identity) | titleCase}}
</span>
zone.js:478未处理的承诺拒绝:模板解析错误:
找不到管道“titleCase”(“接头”)
class=“tag black text pointer”[ngClass]=“{'strike':participantsDiff()}”>[错误->]
{{identityHelperService.getName(identity)| titleCase}
我是否缺少我的pipes模块需要向其他模块提供管道的其他提供者?看起来您只需要将导出添加到您的PipesModule中
exports: [
AbbrDay,
TitleCase,
ToDate,
]
您还应该使用CommonModule
而不是BrowserModule