liveBook · Manning

:host selector

As explained in Pro Angular 16

The :host selector is a CSS selector that targets the host element of an Angular component.

The :host selector targets an Angular component's host element. Angular view encapsulation requires it when styles must respond to an attribute applied to the component itself rather than only to elements inside its template. section 28.3.2

Styling a disabled custom button

A disabled customButton component can style its internal button by combining :host[disabled] with the button's :disabled state. This supports both disabling the host component and disabling the native button. section 28.3.2

...
:host[disabled] button[class*="custom-button-"], 
        button[class*="custom-button-"]:disabled  {
    background-color: material.get-color-from-palette($bg, disabled-button);
    color: material.get-color-from-palette($fg, disabled-button);
}
...

Inspect the SCSS selector that applies Angular Material disabled-button foreground and background colors when either the component host or internal button is disabled. section 28.3.2

How Pro Angular 16 covers it

How deep it goes
Explains the selector through one disabled-button rule and stops short of broader selector mechanics.
Examples
Uses a customButton component whose host and internal button receive disabled-state theme colors.
What it assumes
Assumes familiarity with Angular components, component styles, CSS selectors, and disabled attributes.
What you can do after
Apply the selector to style component internals when an attribute such as disabled is placed on the host element.
How it connects
Connects Angular view encapsulation with CSS selectors, SCSS, component styling, and Angular Material themes.

Also explained in

Compare how 2 books explain :host selector →

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.