DEV Community

Nhan Nguyen
Nhan Nguyen

Posted on

Angular Directive Selector

Image description

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:

Top comments (0)