<分区>
我必须遍历模板内的对象键,所以我制作了这个自定义管道:
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.ts
和 app.component.ts
中声明它。
谢谢。