I have a custom pipe I use in the HTML part of a component. It is declared in the module:
declarations: [ I18nPipe ],
I want to be able to call a method on it from the component code (not the transform
method).
I was hoping that the pipe instance is living somewhere in the dependency injection context so that I can grab it. But I was wrong. If I inject it in the constructor of the component (like any normal service, for example):
constructor(private i18nPipe: I18nPipe)
then I got an error: no providers. So I include it in the providers
section of the same module:
providers: [ I18nPipe ]
then I will have access to it in the component code but there will be two instances of my custom pipe.
created by
providers
, available in DI context. I will get this instance when injected in the constructor, so I will work with this instance in my component code.the instance that is used in the HTML. Where does it live? I want access to this instance in my component code, not to the "provided" one; how can I obtain it?