DEV Community

Nhan Nguyen
Nhan Nguyen

Posted on

4 1

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:

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay