projects/i-components/src/lib/pipes/toinjector.pipe.ts
Pipe for creating an injector given an object
Given that this is a pure pipe this class is useful to create custom injectors when using ngComponentOutlet in template controls
Name | toInjector |
Pure | true |
transform |
transform(value: any, dContext: any)
|
Returns :
any
|
import { Injector, Pipe, PipeTransform } from '@angular/core';
import {
TEMPLATE_COMPONENT_CONTEXT,
TEMPLATE_DECLARING_CONTEXT,
} from '@mobilize/wms-framework';
/**
* Pipe for creating an injector given an object
*
* Given that this is a *pure* pipe this class is useful to
* create custom injectors when using *ngComponentOutlet* in template controls
*
* @export
* @class ToInjectorPurePipe
* @implements {PipeTransform}
*/
@Pipe({
name: 'toInjector',
pure: true,
})
export class ToInjectorPurePipe implements PipeTransform {
constructor(private injector: Injector) {}
transform(value: any, dContext: any = null): any {
return Injector.create({
providers: [
{
provide: TEMPLATE_COMPONENT_CONTEXT,
useValue: value,
deps: [],
},
{
provide: TEMPLATE_DECLARING_CONTEXT,
useValue: dContext,
deps: [],
},
],
parent: this.injector,
});
}
}