0

My intention is to use one pipe (LanguagePipe) from another pipe (DynamicPipe):

import { Pipe, PipeTransform } from '@angular/core';
import { LanguagePipe } from "./language.pipe"

@Pipe({
  name: 'dynamic'
})
export class DynamicPipe implements PipeTransform {

  public constructor(private language: LanguagePipe) { }

  transform(value: any, pipeName: any): any {
    .....
    return this.language.transform(value);
    
  }
}

This worked well. What I want to do is to make it custom so I can use another pipe without importing and declaring it.

...
  public constructor(private injector: Injector) { }

  transform(value: any, pipeName: any): any {
    .....
    //I tried to use the same pipe (language) for testing.
    let pipe = this.injector.get("language");
    return pipe.transform(value);
    
  }
...

But then I get this error:

enter image description here

Here is my reference Dynamic pipe in Angular 2

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
auliaguss
  • 15
  • 4
  • In the attached answer they are passing the actual pipe as an argument (see `myPipe = PercentPipe;`). Here you're attempting to inject the string `"language"` which obviously isn't possible. If you were to follow the attached post step for step, there wouldn't be a need for this question. – ruth Jul 07 '21 at 11:18

0 Answers0