File

projects/i-components/src/lib/pipes/toinjector.pipe.ts

Description

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

Metadata

Name toInjector
Pure true

Methods

transform
transform(value: any, dContext: any)
Parameters :
Name Type Optional Default value
value any No
dContext any No null
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,
    });
  }
}

result-matching ""

    No results matching ""