HostBinding class

Declares a host property on the host component or element.

This annotation is valid on:

  • Public class members
  • The class members may either be fields or getters
  • The class members may either be static or instance

This annotation is inherited if declared on an instance member.

If hostPropertyName is not specified, it defaults to the property or getter name. For example in the following, 'title' is implicitly used:

@Directive(...)
class ImplicitName {
  // Same as @HostBinding('title')
  @HostBinding()
  final title = 'Hello World';
}

These bindings are nearly identical to using the template syntax to set properties or attributes, and are automatically updated if the referenced class member, instance or static, changes:

@Directive(...)
class HostBindingExample {
  // Similar to <example [value]="hostValue"> in a template.
  @HostBinding('value')
  String hostValue;

  // Similar to <example [attr.debug-id]="debugId"> in a template.
  @HostBinding('attr.debug-id')
  String debugId;
}
Annotations
  • @Target({TargetKind.field, TargetKind.getter})

Constructors

HostBinding([String? hostPropertyName])
const

Properties

hashCode int
The hash code for this object.
no setterinherited
hostPropertyName String?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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