Allow read Injector in ViewChild / ContentChild · Issue #47760 · angular/angular · GitHub
Skip to content

Allow read Injector in ViewChild / ContentChild  #47760

Description

@montella1507

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Motivation:

  • the content of ng-template will get the injector from the component, where is the defined, not "instanced"
  • to change this behavior we have ngTemplateOutletInjector
  • we usually need to get the injector of the component, where we are projecting the template into
  • we cannot read the injector via ViewChild.read so we have to workaround this limitation with directive injectore

Usage:

  • there is 100% need of this for writing of the Wrapper components around 3rd party components, which support custom templates (for example dropdowns and tables in Material / PrimeNG / Kendo etc)

PLEASE CHECK this stackblitz:

https://stackblitz.com/edit/angular-ivy-5s8bhd?file=src/app/wrapper/wrapper.component.ts

There is Original and OriginalChild component - to simulate 3rd party components... For the instance... and pSortColumn directives from PrimeNG https://www.primefaces.org/primeng/table - pSortColumn has to get Table component via its constructor)

Proposed solution

ViewChild(ren)/ContentChild(ren) should provida injector via { read: Injector } options.

Alternatives considered

Workaround via directive on the element.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions