decorator
Decorator that marks a DOM property as a host-binding property and supplies configuration metadata. Angular automatically checks host property bindings during change detection, and if a binding changes it updates the host element of the directive.
Option | Description |
---|---|
hostPropertyName? |
The DOM property that is bound to a data property. |
hostPropertyName |
---|
The DOM property that is bound to a data property. |
|
The following example creates a directive that sets the valid
and invalid
properties on the DOM element that has an ngModel
directive on it.
@Directive({selector: '[ngModel]'}) class NgModelStatus { constructor(public control: NgModel) {} @HostBinding('class.valid') get valid() { return this.control.valid; } @HostBinding('class.invalid') get invalid() { return this.control.invalid; } } @Component({ selector: 'app', template: `<input [(ngModel)]="prop">`, }) class App { prop; }
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v10.angular.io/api/core/HostBinding