我必须遍历模板内的对象键,因此我创建了这个自定义管道:
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
。谢谢。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句