javascript - 自定义管道未正确导入

标签 javascript angular typescript ionic-framework ionic2

<分区>

我必须遍历模板内的对象键,所以我制作了这个自定义管道:

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 {}

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

Argument of type '{ selector: string; templateUrl: string; pipes: typeof KeysPipe[]; }' is not assignable to parameter of type 'Component'. Object literal may only specify known properties, and 'pipes' does not exist in type 'Component'.

有什么想法吗?我没有在 app.module.tsapp.component.ts 中声明它。 谢谢。

最佳答案

很长一段时间以来,@Component() 中不再有管道

现在是

@NgModule({
  declarations: [ KeysPipe ]

另见 Select based on enum in Angular2

关于javascript - 自定义管道未正确导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40932265/

相关文章:

javascript - 如何链接 `element` 和 `element.all` ?

javascript - 使用 Knockout、Breeze、Durandal 搜索可观察数组

Angular2 电子邮件验证

javascript - ngModel 绑定(bind)未触发 Angular 输入事件

英雄 Angular 之旅 : Why is one assigned with colon and another by equal signs

javascript - Angular 6 - httpClient不向特定网址发送获取请求

javascript - 这在 JavaScript 中叫什么 :"AnyName: function(param){//code}"(不带引号)

javascript - Node 上的文件创建问题

angular - 在 Angular 中制作确认对话框的简单方法?

Angular 2 模块没有导出成员