[英]Why can't my Angular2 rc5 component find my shared pipe?
我正在努力將項目更新到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 {
}
在另一個模塊中我想使用TitleCase管道,所以我嘗試導入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>
我錯過了我的管道模塊需要將管道提供給其他模塊的其他供應商嗎?
看起來您只需要向PipesModule添加exports
exports: [
AbbrDay,
TitleCase,
ToDate,
]
您還應該使用CommonModule
而不是BrowserModule
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.