projects/i-components/src/lib/pipes/xamGridToInjector.pipe.ts
Pipe to create an injector from a given object.
Given that this is a pure pipe this class is useful to create custom injectors when using ngComponentOutlet in template controls.
Name | xamGridToInjector |
Pure | true |
transform | ||||||
transform(value: any)
|
||||||
Transform the given value into an injector.
Parameters :
Returns :
any
{*} |
import { Injector, Pipe, PipeTransform } from '@angular/core';
/**
* Pipe to create an injector from a given object.
*
* Given that this is a *pure* pipe this class is useful to create custom
* injectors when using *ngComponentOutlet* in template controls.
*
* @export
* @class XamGridToInjectorPurePipe
* @implements {PipeTransform}
*/
@Pipe({
name: 'xamGridToInjector',
pure: true,
})
export class XamGridToInjectorPurePipe implements PipeTransform {
/**
* Creates an instance of XamGridToInjectorPurePipe.
*
* @param {Injector} injector
* @memberof XamGridToInjectorPurePipe
*/
constructor(private injector: Injector) {}
/**
* Transform the given value into an injector.
*
* @param {*} value
* @return {*} {*}
* @memberof XamGridToInjectorPurePipe
*/
transform(value: any): any {
return Injector.create({
providers: [
{
provide: value.constructor,
useValue: value,
deps: [],
},
],
parent: this.injector,
});
}
}