How to use the handset in two different Angular modules

I have a pipe

@Pipe({name: 'keys'})
export class KeysPipe implements PipeTransform {
  transform(value, args:string[]) : any {
  .....
    return keys;
  }
}

I have two modules in which I should use this. If I do something similar in both modules, I get the error message “Two modules declare KeysPipe”

Module1, Module2:

declarations: [KeysPipe],

Then I tried to export KeysPipe through its own module so that I could import it into two modules in which I need to use it.

@NgModule({
    declarations: [ KeysPipe],
})
export class KeysPipeModule {
}

Now I import KeysPipeModule into two modules, I need to use KeysPipe

Module1, Module2:

imports: [KeysPipeModule],

But now I get another template error saying that the pipe was not found. "Cannot find the" keys "of the channel (" v * ngIf = "docalc"> "

+4
1

, , , - KeysPipeModule. :

@NgModule({
    declarations: [ KeysPipe],
    exports: [KeysPipe]
})
export class KeysPipeModule {}
+7

Source: https://habr.com/ru/post/1653610/


All Articles