Skip to content

There is no way to access inputs or outputs of Components created by NgComponentOutlet  #15360

Open

Description

@mcweiss

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
There is no way to set @inputs or subscribe to @output events of the Component created by NgComponentOutlet.

Expected behavior
I expect some to set values and to subscribe events.

What is the motivation / use case for changing the behavior?
At least, we should have the same level of functionality as ViewContainerRef.createComponent() which is roughly the programatic equivalent of NgComponentOutlet. That function returns a ComponentRef<any> which provides an instance property that allows direct access to the class instance of the Component. The original feature request for NgComponentOutlet defined an event on the directive that would fire and pass this ComponentRef object after creation. This did not make it into the current implementation and I see no other alternatives to access inputs/outputs.

Supporting only Components with no inputs or outputs severely limits the usefulness of NgComponentOutlet.

  • Angular version: 4.0.0-rc.1

Activity

  1. DzmitryShylovich commented on Mar 21, 2017

    @DzmitryShylovich
    Contributor

    We can add events like created/destroyed similar to the router's activated/deactivated. It won't work with * syntax (#12121) but I think it's still better than nothing.

  2. added
    area: common
    feature
    on Mar 22, 2017
  3. matheo commented on Mar 28, 2017

    @matheo
    Contributor

    Then there's no way to get the ComponentRef instance?
    ngComponentOutlet will be limited then to dumb components, still cool hehe
    Thanks for the great work!

  4. DzmitryShylovich commented on Mar 28, 2017

    @DzmitryShylovich
    Contributor

    @matheo why do you need a ComponentRef?

  5. matheo commented on Mar 29, 2017

    @matheo
    Contributor

    Following the Dynamic Component Loader documentation, I would like to use the ComponentRef instance to pass input variables to my dynamic components, as they do there:

    (<AdComponent>componentRef.instance).data = adItem.data;
    
  6. DzmitryShylovich commented on Mar 29, 2017

    @DzmitryShylovich
    Contributor
  7. matheo commented on Mar 29, 2017

    @matheo
    Contributor

    Sweet!! thanks a ton! :)

  8. kaylumah commented on Mar 30, 2017

    @kaylumah

    When would this feature be ready for release, could really use something like this :)

  9. DzmitryShylovich commented on Mar 30, 2017

    @DzmitryShylovich
    Contributor

    If you need this feature asap you can copy paste the directive implementation until it will be merged.

  10. alsoLut commented on Apr 2, 2017

    @alsoLut

    a temporary solution is to pass the data via a simple rxjs observable

  11. yjaaidi commented on Apr 5, 2017

    @yjaaidi
    Contributor

    Hi!

    I think we really need a way to control "inputs" and "outputs". Otherwise, if we grab the reference to the component, it will just get hacky:

    • You'll have to reset the inputs manually instead of letting the change detector do that for you.
    • It will get complicated as soon as you'll have multiple dynamic components like in an "ngFor" with maybe different types of components. It will soon need more code than native JS.
  12. mlc-mlapis commented on Apr 5, 2017

    @mlc-mlapis
    Contributor

    But it is the same situation as in the case of dynamically created component instances, right?

  13. vicb commented on Apr 6, 2017

    @vicb
    Contributor

    /ref #12121

  14. broodjetom commented on Jun 6, 2017

    @broodjetom

    So someone found a way to have @Output() in a dynamically loaded component with ngComponentOutlet. Can someone please give an example on how to have an simple variable passed to the component? I was trying it with provider, since the documentation says to do it that way, but this doesn't seem to work, another issue already adresses this, that how I got here. This is what I have right now.

    <ng-container *ngComponentOutlet="getComponent(item.tag); providers: "myProvider"></ng-container>

    This is inside a *ngFor, where every item has a tag which will be factored to a component which is loaded in the container. But I need data inside that container. It is only one object that I need to send, but I don't know how to. myProvider is an object with two properties: nothing special.

  15. 65 remaining items

  16. added a commit that references this issue on Jun 3, 2024
    1f767b4
  17. jpike88 commented on Jan 15, 2025

    @jpike88

    I need to get at the component instance because right now I'm using ng-dynamic-component for getting at outputs, which I'm then send functions back into the parent in order to call them. The problem is that they may have lost context if they use this in them.

    I see in this ticket there's a request for exposing outputs, but I'd like to ask that the component instance itself is exposed as well. The workaround I'm doing is sending the instance itself back through an output, which works but is a dirty workaround as I have to explicitly set 'this' in a bunch of places to ensure it works correctly.

  18. jpike88 commented on Aug 13, 2025

    @jpike88

    Hello, I saw recently that

    #56320
    #56239

    just got closed, is there any plan to finalize this?

  19. jpike88 commented on Aug 13, 2025

    @jpike88

    Just found #63101, never mind. Thanks guys

  20. added 9 commits that reference this issue on Aug 22, 2025
    4f21740
    cca2b85
    ef4d58b
    7ed83f8
    7cbf6f6
    7977558
    d58d7ae
    814bd50
    eef384e
  21. MaximSagan commented on Nov 23, 2026

    @MaximSagan

    Just found #63101, never mind. Thanks guys

    Still waiting for a response on that one... @JeanMeche

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

Metadata

Metadata

Labels

area: commonfeaturefeature: under consideration

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions