0
私は自分自身でNGでアプリケーションを構築していて、コンポーネントのパイプを共有モジュールから使用して問題を実行しています。共有モジュールのコンポーネント内のパイプ
共有モジュール(他のすべてのものを切り出す):
import { NgModule } from '@angular/core';
import { FilterByPipe, OrderByPipe } from './pipes/index';
@NgModule({
imports: [],
declarations: [FilterByPipe],
exports: [
//Pipes
FilterByPipe,
],
providers: [FilterByPipe]
})
export class SharedModule { }
私の質問は、どのように私は別のコンポーネントのコード内からエクスポートされたパイプFilterByPipe
を使用することができますか?すなわち
export class ViewSomethingComponent implements OnInit {
constructor(private _filterBy: FilterByPipe)
filterSomething(data){ this._filterBy.transform(data,{a:'value'})}
}
私が直接パイプを輸入しようとしているが、その親モジュールから提供されていないとして、それは私に依存の問題を提供します。親モジュールにpipを追加してから、それを依存性注入のプロバイダとして使用する以外に、共有コンポーネントによってエクスポートされたパイプを使用する他の方法はありませんか?
を取得します( '{{someDataが| filterby: 'の値'}}')を注入しようとしていますこれをコントローラに渡すと、クラスが見つからないというエラーが返されます。 – Doug
私は答えを更新しました。より明確な表示のためにこれを見てください:https://stackoverflow.com/questions/35144821/angular-2-4-use-pipes-in-services-and-components –