我的意图是使用另一个管道(DynamicPipe)中的一个管道(LanguagePipe):
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);
}
}
这运作良好。我想要做的是定制它,这样我就可以使用另一个管道而无需导入和声明它。
...
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);
}
...
但后来我得到这个错误: