अब मैं एक कस्टम पाइप 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;
}
}
मैं दो अलग-अलग मॉड्यूल में इस का उपयोग करने की आवश्यकता है नामित बनाया है,
(i) Module1
(ii) 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'
@Sajeetharan app.module _imports_ 'मॉड्यूल 1' और 'मॉड्यूल 2', इसलिए इन मॉड्यूल में पाइप * आयात नहीं किया गया है। यदि आप 'मॉड्यूल 1' में 'साझा मॉड्यूल' आयात करते हैं तो पाइप को 'साझा मॉड्यूल' में आयात किया जाता है और 'मॉड्यूल 1' में निर्यात किया जाता है। – Ledzz