javascript-自定义管道未正确导入
作者:互联网
这个问题已经在这里有了答案: > How to iterate object keys using *ngFor? 4个
我必须遍历模板内的对象键,所以我做了这个自定义管道:
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中声明它.
谢谢.
解决方法:
由于相当长一段时间,@ Component()中不再有管道.
现在是
@NgModule({
declarations: [ KeysPipe ]
另见Select based on enum in Angular2
标签:angular,typescript,ionic-framework,ionic2,javascript 来源: https://codeday.me/bug/20191026/1936730.html