All Angular Directives have a selector, which specifies which HTML elements will the directive work with.
Most often, the selector is an attribute selector, which means that the directive will essentially be a custom HTML attribute.
However, Angular directives can be much more than just custom attributes:
⭐ Non-custom attribute selectors
⭐ Attribute selectors with values
⭐ Class selectors
⭐ Combining selectors
⭐ etc
But it can not ⛔ target child-parent relations. Angular Directive selector is impossible to target elements that are children of some specific parents only.
Angular just picked the last element from the confusing (from its perspective) selector and applied the directive to it.
So, no complex parent-child (or sibling, ancestor, descendant, etc.) relations for directive selectors. Remember, Angular directive selectors are not exactly CSS selectors.
I hope you found it helpful. Thanks for reading. 🙏
Let's get connected! You can find me on:
- Medium: https://medium.com/@nhannguyendevjs/
- Dev: https://dev.to/nhannguyendevjs/
- Hashnode: https://nhannguyen.hashnode.dev/
- Linkedin: https://www.linkedin.com/in/nhannguyendevjs/
- X (formerly Twitter): https://twitter.com/nhannguyendevjs/
- Buy Me a Coffee: https://www.buymeacoffee.com/nhannguyendevjs
Top comments (0)