on property

String? on
final

An optional reference for targeting specific instances within a template.

This field is only valid when this is the root instance of a directive type (i.e. not a nested type argument).

By default, this types all directives of T's raw type. However, if this field is non-null, only those whose host elements have a matching reference name are typed.

A Typed declaration that specifies this field takes precedence over one that doesn't when the host element has a matching reference.

@Component(
  ...
  template: '''
    <!-- Defaults to GenericComponent<String> -->
    <generic></generic>
    <!-- The reference marks this as GenericComponent<int> -->
    <generic #indexed></generic>
  ''',
  directives: [
    GenericComponent,
  ],
  directiveTypes: [
    // Applies to <generic> by default.
    Typed<GenericComponent<String>>(),
    // Applies to <generic #indexed> only.
    Typed<GenericComponent<int>>(on: 'indexed'),
  ],
)
class ExampleComponent {}

This field must be distinct between two Typed declarations for the same directive of T's raw type in the same view.

Implementation

final String? on;