这个问题在这里已有答案:
我必须遍历模板中的对象键,所以我创建了这个自定义管道:
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 {}
但是,当我构建项目时,会发生以下错误:
类型'{selector:string; templateUrl:string;管道:typeof KeysPipe []; }'不能分配给'Component'类型的参数 . 对象文字只能指定已知属性,“组件”类型中不存在“管道” .
任何的想法 ?我没有在 app.module.ts
和 app.component.ts
中声明它 . 谢谢 .
1 回答
自从很长一段时间以来,
@Component()
中就没有pipes
了 .现在是
另见Select based on enum in Angular2