liveBook · Manning

Shadow host

As explained in Pro Angular 16

A host element is the HTML element affected by an Angular binding through changes to its appearance, content, or behavior.

A host element is the HTML element a binding acts on. A binding can change its appearance, content, or behavior. Any HTML element in a template can host a binding, and one element can have multiple bindings that manage different aspects. section 11.2 section 11.2.4

Changing a host’s appearance

In `<div [ngClass]="classes()">Hello, World.</div>`, the div is the host. Angular evaluates `classes()` and passes its result to the `ngClass` directive, which changes the div’s CSS classes. section 11.2

For an event binding, the host plays the opposite role: it sends an event into the application. In a product table, `(mouseover)="selectedProduct.set(item.name)"` makes a `td` the event source. A separate binding can then highlight the selected row. section 13.2

Directives and components also use host elements. An attribute directive can read configuration from its host’s attributes and add CSS classes to that element. A component selector identifies its host; Angular then populates the matching element with the component’s template. section 14.3.1 section 16.2.1

How Pro Angular 16 covers it

How deep it goes
Defines the host’s role and illustrates binding, event, directive, and component behavior without detailing rendering internals.
Examples
Uses a div with `ngClass`, a table cell handling `mouseover`, configured directive attributes, and component elements in a template.
What it assumes
Assumes familiarity with HTML elements and JavaScript expressions while explaining Angular binding syntax and component selector matching.
What you can do after
Apply it via Angular templates to identify which element a binding changes, sends an event, configures a directive, or hosts a component.
How it connects
Connects host elements to one-way bindings, event bindings, attribute directives, component selectors, and templates.

Also explained in

Compare how 2 books explain shadow host →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.