angular - Angular2 rc5 bileşenim neden paylaşılan pipe’ımı bulamıyor?
Bir projeyi rc5'e güncellemeye çalışıyorum ve tüm uygulamam için tüm direktifleri, pipe'ları vs. yükleyen bir ana modül oluşturarak başladım. Bunu çalıştırdım ve her şey yolundaydı. Şimdi bu ana modülü, uygulamamın yapısı ve kullanımı açısından mantıklı olan daha küçük modüllere ayırmaya çalışıyorum. Uygulamamın, birden fazla bileşen tarafından paylaşılan tüm pipe'ları saklayan bir modüle sahip olmasını istedim, bu yüzden bu modülü oluşturdum:
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 {
}
Başka bir modülde TitleCase borusunu kullanmak istiyorum, bu yüzden PipesModule'u içe aktarmayı denedim:
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 {
}
Uygulamayı çalıştırdığımda bu hatayı çalışma zamanında alıyorum:
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>
Diğer modüllere pipe'larını sunmak için pipes modülümün sunması gereken başka bir sağlayıcıyı mı kaçırıyorum?
Cevap #1
Görünüşe göre PipesModule'unuza exports eklemeniz gerekiyor
exports: [
AbbrDay,
TitleCase,
ToDate,
]
BrowserModule yerine CommonModule kullanmalısınız
