2

I need to do some tasks inside a component which require non-transformed text. Yet I want to be able to pass pipes alongside the text. I would like to either pass the pipes as parameters for the component and call them later - or if that is not possible, delay the execution of the transformations and inject my own before that. I can not use my own pipe since it

  1. would require all other pipes to be called afterwards and

  2. is a stateful transformation (I need to know if the text is currently collapsed or not)

I tried simply passing the pipes in an array to an @Input field in the component, and I tried to pass them as strings and then resolve the pipe-names to retrieve the pipe-instances, both unsuccessfully. My first approach was to create a pipe of my own, but since I need to store the state of the text I can't really use pipes.

This was how I would like to set up my component (which does not work obviously)

<collapsible-content [text]="item.data.message" 
   [pipes]="[markdown, hashtags, mention]">
</collapsible-content>
FinnSo
  • 41
  • 1
  • Pipes aren't dependencies or providers. You can simply create them with `new MyPipe(...)` and use them. –  May 13 '19 at 12:27
  • [In case it helps](https://stackoverflow.com/questions/48183677/how-to-format-date-in-component-of-angular-5/48183927#48183927) –  May 13 '19 at 12:28
  • Thanks, but that still does not really solve my issue since I don't want to statically instantiate them, I want to be able to pass the pipes I want to use via parameter to the component. – FinnSo May 13 '19 at 12:30
  • Then you instanciate them and pass them to the inputs ... Although I'm not sure this is a good practice. Instead, you could create a service with the `transform` you have already coded, and let the pipe call it, as well as your components. –  May 13 '19 at 12:31

0 Answers0