Directive class

An annotation that marks a class as an Angular directive, allowing you to attach behavior to elements in the DOM.

import 'dart:html';

import 'package:ngdart/angular.dart';

@Directive(selector: '[myHighlight]')
class HighlightDirective {
  HighlightDirective(Element el) {
    el.style.backgroundColor = 'yellow';
  }
}

Use @Directive to mark a class as an Angular directive and provide additional metadata that determines how the directive should be processed, instantiated, and used at runtime.

In addition to the metadata configuration specified via the Directive decorator, directives can control their runtime behavior by implementing various lifecycle hooks.

See also:

Implementers
Annotations
  • @Target({TargetKind.classType})

Constructors

Directive({required String selector, List<Object> providers = const [], String? exportAs, Visibility visibility = Visibility.local})
const

Properties

exportAs String?
A name that can be used in the template to assign this directive to a variable.
final
hashCode int
The hash code for this object.
no setterinherited
providers List<Object>
The set of injectable objects that are visible to the directive and its light DOM children.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selector String
The CSS selector that triggers the instantiation of the directive.
final
visibility Visibility
Whether this directive will be provided for injection.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited