2017-06-30 13 views
1

角度見つかりませんでした私は、角度4で私のカスタムパイプを実装する必要がありますが、私はこのカスタムパイプを使用しようとするコンポーネントで、私は次のエラーがあります。カスタムパイプ4

<div>{{ selected.lastModifiedDate | formatdate}}</div> 

Template parse errors: The pipe 'formatdate' could not be found

私を現時点では、カスタムパイプが空である:

formatdate.pipe

import { Pipe, PipeTransform } from '@angular/core'; 

@Pipe({ 
    name: 'formatdate' 
}) 

export class FormatdatePipe implements PipeTransform { 

    transform(value: any, args?: any): any { 
    return null; 
    } 
} 

私持っ共有パイプモジュール

pipe.module

import { NgModule } from '@angular/core'; 
import { FormatdatePipe } from '../pipes/formatdate.pipe'; 

@NgModule({ 
    imports: [], 
    declarations: [FormatdatePipe], 
    exports: [FormatdatePipe], 
}) 

export class PipeModule { 

    static forRoot() { 
    return { 
     ngModule: PipeModule, 
     providers: [], 
    }; 
    } 
} 

そして

import { PipeModule } from './shared/pipes/pipe.module'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 

    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    RouterModule.forRoot(routes), 
    PipeModule.forRoot(), 
.... 

問題がある私の主なアプリモジュール

app.moduleで?多分モジュールで何か

+0

パイプモジュールを作成した理由はありますか?これは不要です。 app.module宣言にパイプをインクルードするだけです。 https://stackoverflow.com/documentation/angular2/1165/pipes/3756/custom-pipes#t=201706301331556332039 –

+0

それは私はすでに私はインポートする場合、それは動作します – Alessandro

+0

このエラーを持っているので、私はモジュールを作成した、変更されません。あなたはそれをインポートする必要が – Alessandro

答えて

3

あなたが輸入、app.moduleのごdeclarationsにモジュールをインポートする必要はありません。

import { PipeModule } from './shared/pipes/pipe.module'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    PipeModule.forRoot() 
    ], 
    imports: [ 
    BrowserModule, 
    ....... 
+0

引数:(typeof演算AppComponent | {ngModule:typeof演算PipeModule;プロバイダー:任意[];})]。 imp ... 'は' NgModule '型のパラメータに代入できません。プロパティの宣言の型は互換性がありません。タイプ '(typeof演算AppComponent | {ngModule:typeof演算PipeModule;プロバイダは:任意[];})[]' '(|タイプ任意[])[]' を入力する割り当て可能ではありません。タイプ 'タイプのAppComponent | {ngModule:PipeModuleの型。プロバイダ:any []; } 'は型に割り当てられません' any [] |タイプ 'と入力します。タイプ '{ngModule:typeof PipeModule;プロバイダ:any []; } 'は型に割り当てられません' any [] |タイプ 'と入力します。 – Alessandro

+2

どうしてそう思うのですか? – yurzui

関連する問題