File

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

Description

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.

Metadata

Name xamGridToInjector
Pure true

Methods

transform
transform(value: any)

Transform the given value into an injector.

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

result-matching ""

    No results matching ""