HostListener class

Declares listening to eventName on the host element of the directive.

This annotation is valid on instance methods of a class annotated with either @Directive or @Component, and is inherited when a class implements, extends, or mixes-in a class with this annotation.

@Component(
  selector: 'button-like',
  template: 'CLICK ME',
)
class ButtonLikeComponent {
  @HostListener('click')
  void onClick() {}
}

An optional second argument, args, can define arguments to invoke the method with, including a magic argument '\$event', which is replaced with the value of the event stream. In most cases args can be inferred when bound to a method with a single argument:

@Component(
  selector: 'button-like',
  template: 'CLICK ME',
)
class ButtonLikeComponent {
  @HostListener('click') // == @HostListener('click', const ['\$event'])
  void onClick(MouseEvent e) {}
}

Constructors

HostListener(String eventName, [ List<String> args ])
const

Properties

args → List<String>
final
eventName → String
final
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited