我有一个定制的管道命名为 CurrConvertPipe
import {Pipe, PipeTransform} from '@angular/core';
import {LocalStorageService} from './local-storage';
@Pipe({name: 'currConvert', pure: false})
export class CurrConvertPipe implements PipeTransform {
constructor(private currencyStorage: LocalStorageService) {}
transform(value: number): number {
let inputRate = this.currencyStorage.getCurrencyRate('EUR');
let outputputRate = this.currencyStorage.getCurrencyRate(localStorage.getItem('currency'));
return value / inputRate * outputputRate;
}
}
我需要在两个不同的模块中使用它,Module1
和 Module2
。
当我导入 Module1
和 Module2
时,我得到一个错误,说明它应该在更高级别的模块中声明。
所以我声明了 app.module.ts
中的管道
import './rxjs-extensions';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CurrConvertPipe } from './services/currency/currency-pipe';
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule,
Module1,
Module2
],
declarations: [
AppComponent,
CurrConvertPipe
],
providers: [
],
bootstrap: [AppComponent]
})
export class AppModule { }
但是当我在 Module1
中使用它时,它会抛出一个错误
找不到管道“ currConvert”