File

projects/i-components/src/lib/pipes/xamGridTemplateToinjector.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 xamTemplateToInjector
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 XamTemplateToInjectorPurePipe
 * @implements {PipeTransform}
 */
@Pipe({
  name: 'xamTemplateToInjector',
  pure: true,
})
export class XamTemplateToInjectorPurePipe 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 ""