-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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(core): add API to inject attributes on the host node #54604
Conversation
ce6a023
to
3487af0
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.
reviewed-for: public-api
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.
LGTM
Reviewed-for: public-api
Reviewed-for: fw-core
Angular has the `@Attribute` decorator that allows for attributes to be injected from the host node, but we don't have an equivalent for the `inject` function. These changes introduce the new `HostAttributeToken` class that can be used to inject attributes similarly to `@Attribute`. It can be used as follows: ```typescript import {HostAttributeToken, inject} from '@angular/core'; class MyDir { someAttr = inject(new HostAttributeToken('some-attr')); } ``` The new API works similarly to `@Attribute` with one key exception: it will throw a DI error when the attribute doesn't exist, instead of returning `null` like `@Attribute`. We made this change to align its behavior closer to other injection tokens.
3487af0
to
60b7c08
Compare
This PR was merged into the repository by commit 331b16e. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Angular has the
@Attribute
decorator that allows for attributes to be injected from the host node, but we don't have an equivalent for theinject
function. These changes introduce the newHostAttributeToken
class that can be used to inject attributes similarly to@Attribute
. It can be used as follows:The new API works similarly to
@Attribute
with one key exception: it will throw a DI error when the attribute doesn't exist, instead of returningnull
like@Attribute
. We made this change to align its behavior closer to other injection tokens.