繁体   English   中英

为什么我的Angular2 rc5组件找不到我的共享管道?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM