【发布时间】:2017-04-17 08:49:19
【问题描述】:
我必须遍历模板内的对象键,所以我制作了这个自定义管道:
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; 类型的参数模板网址:字符串;管道:typeof KeysPipe[]; }' 不可分配给“组件”类型的参数。对象字面量只能指定已知属性,而“组件”类型中不存在“管道”。
有什么想法吗?我没有在app.module.ts 和app.component.ts 中声明它。
谢谢。
【问题讨论】:
标签: javascript angular typescript ionic-framework ionic2