我有一个自定义管道,名为 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”