selector property

String selector
final

The CSS selector that triggers the instantiation of the directive.

Angular only allows directives to trigger on CSS selectors that do not cross element boundaries.

The selector may be declared as one of the following:

  • element-name: select by element name.
  • .class: select by class name.
  • [attribute]: select by attribute name.
  • [attribute=value] : select by attribute name and value.
  • :not(sub_selector): select only if the element does not match the sub_selector.
  • selector1, selector2: select if either selector1 or selector2 matches.

Example

Suppose we have a directive with an input[type=text] selector and the following HTML:

<form>
  <input type="text">
  <input type="radio">
</form>

The directive would only be instantiated on the <input type="text"> element.

Implementation

final String selector;