You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
There is no way to access inputs or outputs of Components created by NgComponentOutlet #15360
area: commonIssues related to APIs in the @angular/common packagefeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration
[ ] 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
Reacted by TheILPlace, Mateo Tibaquirá, Younes Jaaidi, Marek Buko, Rodolfo Nogueira, Yuriy Grunin, Dino Bettini, Jonathan Gelin, Meligy, Eticom Ltd and 136 more
Reacted by Paul Lunt, Ori Shalom, gentoo90, 1van0v, Pablo Maurer, David Silva, marsc and Marin Muštra
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.
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!
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:
Reacted by Ctibor Laky, Naga Babu, Mitja O., Sateesh Kumar, Rodolfo Nogueira, Jason K., Darius Juodokas, Code Scratcher, Pablo Maurer and Marlon Eduardo Peña Llanos
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.
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.
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.
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.
area: commonIssues related to APIs in the @angular/common packagefeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration
Activity
DzmitryShylovich commentedon Mar 21, 2017
We can add events like
created/destroyedsimilar to the router'sactivated/deactivated. It won't work with*syntax (#12121) but I think it's still better than nothing.matheo commentedon Mar 28, 2017
Then there's no way to get the
ComponentRefinstance?ngComponentOutletwill be limited then to dumb components, still cool heheThanks for the great work!
DzmitryShylovich commentedon Mar 28, 2017
@matheo why do you need a
ComponentRef?matheo commentedon Mar 29, 2017
Following the Dynamic Component Loader documentation, I would like to use the
ComponentRefinstance to pass input variables to my dynamic components, as they do there:DzmitryShylovich commentedon Mar 29, 2017
@matheo
createevent will contain a component instance https://github.com/angular/angular/pull/15362/files#diff-8f1a604d8ceede1c4382f059e94239c9R110matheo commentedon Mar 29, 2017
Sweet!! thanks a ton! :)
kaylumah commentedon Mar 30, 2017
When would this feature be ready for release, could really use something like this :)
DzmitryShylovich commentedon Mar 30, 2017
If you need this feature asap you can copy paste the directive implementation until it will be merged.
alsoLut commentedon Apr 2, 2017
a temporary solution is to pass the data via a simple rxjs observable
yjaaidi commentedon Apr 5, 2017
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:
mlc-mlapis commentedon Apr 5, 2017
But it is the same situation as in the case of dynamically created component instances, right?
vicb commentedon Apr 6, 2017
/ref #12121
broodjetom commentedon Jun 6, 2017
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.myProvideris an object with two properties: nothing special.65 remaining items
feat(common): Expose `NgComponentOutlet` outputs.
jpike88 commentedon Jan 15, 2025
I need to get at the component instance because right now I'm using
ng-dynamic-componentfor 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 usethisin 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.
jpike88 commentedon Aug 13, 2025
Hello, I saw recently that
#56320
#56239
just got closed, is there any plan to finalize this?
jpike88 commentedon Aug 13, 2025
Just found #63101, never mind. Thanks guys
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
feat(common): Expose `NgComponentOutlet` outputs.
ngComponentOutletinput/output/two-way binding + directives #63099 as a duplicate of this issueMaximSagan commentedon Nov 23, 2026
Still waiting for a response on that one... @JeanMeche