自定义管道未正确导入

时间:2016-12-02 12:28:02

标签: javascript angular typescript ionic-framework ionic2

我必须迭代模板中的对象键,所以我制作了这个自定义管道:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:eb1="http://rep.evenex.dk/schema/evenex/eBusiness_01"
exclude-result-prefixes="eb1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="eb1:EANNo">
    <xsl:copy>
        <xsl:value-of select="format-number(., '0000000000000')"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

在我的页面中,它按以下方式导入:

import {PipeTransform, Pipe} from "@angular/core";

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

但是当我构建项目时会出现这个错误:

  

类型的参数&#39; {selector:string; templateUrl:string;管道:typeof KeysPipe []; }&#39;不能分配给&#39;组件&#39;类型的参数。对象文字只能指定已知属性,并且“管道”和“管道”可以指定。类型&#39;组件&#39;。

中不存在

有什么想法吗?我没有在import {KeysPipe} from "../../pipes/keys-pipe"; import {Component} from '@angular/core'; @Component({ selector: 'page-history', templateUrl: 'history.html', pipes: [ KeysPipe ] }) export class HistoryPage {} app.module.ts中声明它。 感谢。

1 个答案:

答案 0 :(得分:4)

很久以来pipes中就没有@Component()了。

现在是

@NgModule({
  declarations: [ KeysPipe ]

另见Select based on enum in Angular2

相关问题