【问题标题】:how to create a pipe module angular如何创建管道模块角度
【发布时间】:2017-12-04 17:00:27
【问题描述】:

我有一个模块,它是一组管道,当我尝试在我的应用程序中安装这个模块时,它说找不到 xxx 管道 我的 app.module 看起来像这样:

   import { PipesModule } from '@Pricetravel/pipes.module';
@NgModule({
  declarations: [
    AppComponent,

  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing,
    PipesModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

有没有一种特殊的方法来创建管道模块?还是特殊的导入方式? 谢谢和问候!!

【问题讨论】:

  • 你是否在 PipesModule 中添加了你的 piples 的声明,类的导出完成了吗?
  • 是的,这是我的 pipe.module : import { Round } from './components/pipes/round.pipe'; @NgModule({ 声明:[ Round ],导入:[CommonModule],}) 导出类 PipeModule { }
  • 检查答案你忘了在你的管道模块中包含 export: 属性

标签: angular


【解决方案1】:

这是pipes.module.ts 的示例:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UnescapePipe } from './pipes/unescape.pipe';
import { HtmlDecodePipe } from './pipes/html-decode.pipe';


@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [UnescapePipe, HtmlDecodePipe],
  exports: [UnescapePipe, HtmlDecodePipe]
})
export class PipesModule { }

【讨论】:

    【解决方案2】:

    您还必须导出管道类,要在模块中导出管道类,您必须在模块的导出属性中写入类的名称。

    在您在注释中给出的代码中,您忘记导出,这就是为什么您没有在使用 piple 模块的另一个模块中的模块中声明 piple。

    @NgModule({
      declarations: [ MyFilter],
      imports: [],
      exports:[MyFilter],//export list here 
      providers: []
    })
    export class PipleModule { }
    

    【讨论】:

    • 非常感谢,我选择这个作为最佳答案是因为他解释了我的错误,再次感谢你!
    猜你喜欢
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 2021-05-31
    • 1970-01-01
    • 2016-08-05
    相关资源
    最近更新 更多