New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(common): Add an 'outlet' injector option for ngTemplateOutlet #55389
base: main
Are you sure you want to change the base?
Conversation
Question: could this be a fix for #54097 ? |
Hmm I don't think so, the template outlet in that example looks like its already manually doing something pretty similar to what this would do. I tried adding an extra |
0bcd470
to
b13736d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alxhub couple questions for you to make sure I'm on the right track
private _getInjector(): Injector | undefined { | ||
if (this.ngTemplateOutletInjector === 'inherit') { | ||
this._childInjector = | ||
this._childInjector ?? Injector.create({providers: [], parent: this.injector}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure why I need to create a child injector instead of just passing along the current injector, but based on my stackblitz testing it did seem to be necessary. Just wanted to call that out in case I'm doing something wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be necessary I don't think...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a modified version of my stackblitz to show that it really does seem to need me to create a child to get the same behavior as composing with content projection: https://stackblitz.com/edit/stackblitz-starters-9csxbu?file=src%2Fmain.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked to @crisbeto about this. He says this behavior makes sense to him because embedded view injectors can't be injected using inject(Injector)
. By creating the child injector, we create an injector that acts as an embedded injector, but it ends up consulting the node injector for each lookup.
Adds an option (`ngTemplateOutletInjector="outlet"`) that instructs the ngTemplateOutlet to inherit its injector from the outlet's place in the instantiated DOM.
b13736d
to
39afd8c
Compare
Adds an option (
ngTemplateOutletInjector="outlet"
) that instructs the ngTemplateOutlet to inherit its injector from the outlet's place in the instantiated DOM.