自定义管道未正确导入 [英] Custom pipe not correctly imported
问题描述
我必须迭代模板中的对象键,所以我制作了这个自定义管道:
I have to iterate over an object keys inside a template, so I made this custom pipe :
import {PipeTransform, Pipe} from "@angular/core";
@Pipe({name: "keys"})
export class KeysPipe implements PipeTransform {
transform(value: any, args?: any[]): any[] {
return Object.keys(value);
}
}
在我的页面中,它导入如下:
And inside my page it's imported as follow :
import {KeysPipe} from "../../pipes/keys-pipe";
import {Component} from '@angular/core';
@Component({
selector: 'page-history',
templateUrl: 'history.html',
pipes: [ KeysPipe ]
})
export class HistoryPage {}
但是当我构建项目时会出现此错误:
But when i build project there is this error that occurs :
类型'{selector:string; templateUrl:string;管道:typeof KeysPipe []; }'不能分配给'Component'类型的参数。对象文字只能指定已知属性,'组件'类型中不存在'管道'。
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
中声明它。
谢谢。
Any idea ? I didn't declare it in app.module.ts
nor app.component.ts
.
Thanks.
推荐答案
<免费管道
code> @Component()已经有一段时间了。
There is no pipes
in @Component()
anymore since quite some time.
现在它是
@NgModule({
declarations: [ KeysPipe ]
另请参阅基于Angular2中的枚举选择
这篇关于自定义管道未正确导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!