What is HostListener and HostBinding in Angular?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Feb 22, 2018

 

HostListener in Angular is a function decorator. It accepts an event name as the argument and calls the associated function when the event gets fired on the host element.

//example 
@HostListener('mouseover') onHover() { 
  window.alert("hover"); 
} 

Here, when you hover the mouse on the host element, an alert popup will be triggered.

HostBinding is used to bind the input properties in the host element to the directive. With the HostBinding decorator, a directive can link internal property to the input property of the host element. When the internal property is changed, the input property of the host element will change too.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Angular 8 Interview Questions

    What is Angular 8?

    Angular 8 is the latest version of the most popular JavaScript framework that is used to develop front-end mobile apps, desktop apps, and SPAs (Single Page Applications). It is an open-source, typescr...

    Angular 8 Interview Questions

    What new in Angular 8?

    Some of the new features in Angular 8 are,It supports TypeScript 3.4. All the angular 8 applications now need TypeScript 3.4 to run. It now supports the Web worker class. It frees the main thread...

    Angular 8 Interview Questions

    What is Angular CDK?

    Angular CDK (Component Development Kit) is comprised of tools, services, components, classes, and modules that are used by the developers to build components of the web. It represents an abstraction o...