My Pipe located in apps\administrator\src\app\modules\messenger\pipes\custom-message.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
/**
* Pipe for Custom Message for boolean
*/
@Pipe({
name: 'customMessage',
})
export class CustomMessagePipe implements PipeTransform {
public transform(value: boolean, trueString: string, falseString: string): string {
//The code
}
}
In the main module apps\administrator\src\app\app.module.ts
file:
import { CustomMessagePipe } from './modules/messenger/pipes/custom-message.pipe';
...
@NgModule({
declarations: [..., CustomMessagePipe],
providers: [...],
})
export class AppModule {}
Now, I have two modules FormSmsModule
and FormSmtpModule
FormSmsModule
located in apps\administrator\src\app\modules\messenger\form-sms
FormSmtpModule
located in apps\administrator\src\app\modules\messenger\form-smtp
Following this answer https://stackoverflow.com/a/62468805
In the file apps\administrator\src\app\modules\messenger\form-sms\form-sms.module.ts using CustomMessagePipe
on imports
array, I have:
import { CustomMessagePipe } from '../pipes/custom-message.pipe';
@NgModule({
declarations: [...],
imports: [
...,
CustomMessagePipe,
FormSmsRoutingModule,
],
providers: [...],
})
export class FormSmsModule {}
In the file apps\administrator\src\app\modules\messenger\form-smtp\ form-smtp.module.ts using CustomMessagePipe
on imports
array, I have:
import { CustomMessagePipe } from '../pipes/custom-message.pipe';
@NgModule({
declarations: [...],
imports: [
...,
CustomMessagePipe,
FormSmtpRoutingModule,
],
providers: [...],
})
export class FormSmtpModule {}
In this form I have this error like error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class
ERROR in apps/administrator/src/app/modules/messenger/pipes/custom-message.pipe.ts:10:14 - error NG6002: Appears in the NgModule.imports of FormSmsModule, but could not be resolved to an NgModule class.
Is it missing an @NgModule annotation?
10 export class CustomMessagePipe implements PipeTransform {
~~~~~~~~~~~~~~~~~
apps/administrator/src/app/modules/messenger/pipes/custom-message.pipe.ts:10:14 - error NG6002: Appears in the NgModule.imports of FormSmtpModule, but could not be resolved to an NgModule class.
Is it missing an @NgModule annotation?
10 export class CustomMessagePipe implements PipeTransform {
~~~~~~~~~~~~~~~~~
** Angular Live Development Server is listening on localhost:4202, open your browser on http://localhost:4202/ **
Using the alternative method as https://stackoverflow.com/a/40015085
In the file apps\administrator\src\app\modules\messenger\form-sms\form-sms.module.ts using CustomMessagePipe
on declarations
array, I have:
import { CustomMessagePipe } from '../pipes/custom-message.pipe';
@NgModule({
declarations: [..., CustomMessagePipe],
imports: [
...,
FormSmsRoutingModule,
],
providers: [...],
})
export class FormSmsModule {}
In the file apps\administrator\src\app\modules\messenger\form-smtp\form-smtp.module.ts using CustomMessagePipe
on declarations
array, I have:
import { CustomMessagePipe } from '../pipes/custom-message.pipe';
@NgModule({
declarations: [..., CustomMessagePipe],
imports: [
...,
FormSmtpRoutingModule,
],
providers: [...],
})
export class FormSmtpModule {}
I have the error described in this question error Angular 2 - Pipe reuse in multiple modules - error not found or duplicate definition
ERROR in apps/administrator/src/app/modules/messenger/pipes/custom-message.pipe.ts:10:14 - error NG6007: The Pipe 'CustomMessagePipe' is declared by more than one NgModule.
10 export class CustomMessagePipe implements PipeTransform {
~~~~~~~~~~~~~~~~~
apps/administrator/src/app/modules/messenger/form-sms/form-sms.module.ts:47:84
47 declarations: [..., CustomMessagePipe],
~~~~~~~~~~~~~~~~~
'CustomMessagePipe' is listed in the declarations of the NgModule 'FormSmsModule'.
apps/administrator/src/app/modules/messenger/form-smtp/form-smtp.module.ts:47:85
47 declarations: [..., CustomMessagePipe],
~~~~~~~~~~~~~~~~~
'CustomMessagePipe' is listed in the declarations of the NgModule 'FormSmtpModule'.
apps/administrator/src/app/app.module.ts:36:112
36 declarations: [..., CustomMessagePipe],
~~~~~~~~~~~~~~~~~
'CustomMessagePipe' is listed in the declarations of the NgModule 'AppModule'.
** Angular Live Development Server is listening on localhost:4202, open your browser on http://localhost:4202/ **
As you can see, The two solutions implies the another problem.
How solve that?