2016-08-19 24 views
2

我正在將項目更新到rc5,並開始創建一個主模塊,用於加載我的整個應用程序的所有指令,管道等。我把它搞清楚了,一切都很順利。我現在試圖將該主模塊分割成更小的模塊,這對我的應用程序的結構和使用有意義。我想我的應用程序有隻是存儲所有由多個組件共享的管道,所以我提出這個模塊一個模塊:爲什麼我的Angular2 rc5組件找不到我的共享管道?

pipes.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 { 

} 

在另一個模塊,我想用的首字母大寫管,所以我試圖導入PipesModule:

calendar.module.ts

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> 

我是否缺少一些其他供應商,我的管道模塊需要將其管道提供給其他模塊?

回答

14

看起來像你只需要

exports: [ 
    AbbrDay, 
    TitleCase, 
    ToDate, 
] 

你也應該使用CommonModule而不是BrowserModule

添加 exports您PipesModule
相關問題