Angular 6库管道

标签 angular pipe angular6 angular-pipe angular-library

如何在 Angular 6 库中添加自定义管道以使其在我的主应用程序中可用? 目前我正在这样做: lib.module.ts:

@NgModule({
  declarations: [
    SomePipe
  ],
  exports: [
   SomePipe
]})

在 public_api.ts 中:

export * from './lib/pipes/some.pipe';

在 app.module.ts 中:

import { LibModule } from 'lib';
@NgModule({
  ...
  imports: [
    LibModule
  ]
 ...
})

我正在尝试使用管道 {{ 'something' | some}} 但是 SomePipetransform 方法没有被调用。

最佳答案

所以问题似乎出在这里:

export * from './lib/pipes/some.pipe';

当您应该从模块文件中导出模块 (@NgModule) 时,您正在从 some.pipe 文件中导出所有内容。像这样:

export * from './lib.module';

这样做应该可以解决问题。

这是一个 Sample StackBlitz供您引用。

关于Angular 6库管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53396262/

相关文章:

javascript - 如何在每次单击 ion-tab 按钮时执行函数

Angular 2 (RC 1) : Data view not refreshing when data loaded from a file

javascript - 无法将数据发送到 API 服务器 'Error trying to diff ' [对象对象 ]'. Only arrays and iterables are allowed'

javascript - 父子操纵之间的共享值(value)

c++ - 当使用 stdout 输出二进制数据时,如何将调试/详细信息输出到终端?

c - 使用 FIFO(名称管道)重定向标准输入

c++ - 在 64 位 Ubuntu 中使用 pthread 从 void* 转换为 int

html - 如何更改 Angular 6 中 onclick 按钮的 css?

spring - 如何在 Angular 6 中使用 webSocket

angular-ui-router - 数据表内的Angular Material 2 routerlink