微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 如何在两个不同的Angular模块中使用管道

我有一个烟斗

@Pipe({name: 'keys'})
export class KeysPipe implements PipeTransform {
  transform(value, args:string[]) : any {
  .....
    return keys;
  }
}

我有两个模块,我需要使用它.如果我在这两个模块中执行类似的操作,我会收到一条错误消息“两个模块声明了KeysPipe”

Module1,Module2:

declarations: [KeysPipe],

然后我尝试通过它自己的模块导出KeysPipe,以便我可以将它导入到我需要使用它的两个模块中

@NgModule({
    declarations: [ KeysPipe],
})
export class KeysPipeModule {
}

现在我在我需要使用KeysPipe的两个模块中导入KeysPipeModule

Module1,Module2:

imports: [KeysPipeModule],

但现在我得到一个不同的模板错误,说没有找到管道“找不到管道’密钥'(”v * ngIf =“docalc”>“

解决方法:

您在正确的轨道上,您唯一缺少的代码是KeysPipeModule中的导出.它应该是这样的:

@NgModule({
    declarations: [ KeysPipe],
    exports: [KeysPipe]
})
export class KeysPipeModule {}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐