自定义管道未正确导入

塞诺里尔

我必须遍历模板内的对象键,因此我创建了这个自定义管道:

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

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

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

import {KeysPipe} from "../../pipes/keys-pipe";
import {Component} from '@angular/core';
@Component({
  selector: 'page-history',
  templateUrl: 'history.html',
  pipes: [ KeysPipe ]
})
export class HistoryPage {}

但是当我构建项目时,会发生此错误:

类型'{选择符:字符串;templateUrl:字符串; 管道:typeof KeysPipe []; }”不可分配给“组件”类型的参数。对象文字只能指定已知的属性,而“组件”类型中不存在“管道”。

任何的想法 ?我没有在声明它app.module.ts也不是app.component.ts谢谢。

贡特·佐赫鲍尔(GünterZöchbauer)

有没有pipes@Component()了,因为很长一段时间。

现在是

@NgModule({
  declarations: [ KeysPipe ]

另请参阅基于Angular2中的枚举选择

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章