2016-12-02 7 views
3

を輸入していない私は、テンプレート内のオブジェクトキーを反復処理する必要があるので、私はこのカスタムパイプ製: カスタムパイプが正しく

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:文字列;パイプ:タイプKeysPipe []; } 'は' Component '型のパラメータに代入不可能です。オブジェクトリテラルは既知のプロパティのみを指定し、 'pipes'は 'Component'タイプには存在しません。

私はそれをapp.module.tsでもapp.component.tsでも宣言しませんでした。おかげさまで

答えて

4

@Component()にはもうかなりの時間以来、pipesはありません。

今では

@NgModule({ 
    declarations: [ KeysPipe ] 

も参照してくださいSelect based on enum in Angular2

+2

おやおや、素敵な作品です。私はいくつかの古いチュートリアルを読んでいるに違いない...ありがとうalot :) – Senorihl