I'm finding it quite confusing to understand the usage of :host
in Angular.
For instance, let's consider a CSS file named a-component.component.css
and its corresponding HTML file named a-component.component.html
with a selector
of app-a-component
.
Within the CSS file, there is a rule:
h1 {
font-size: 12px;
}
Based on the explanation provided, I believe this CSS rule only affects the <app-a-component>
HTML element, is that correct?
If I modify the CSS to:
:host h1 {
font-size: 12px;
}
(adding :host
)
Will it still target the same <app-a-component>
HTML element since it is the host element of this component?
If both approaches yield the same result, then why would we need to use :host
if it has the same effect with or without it?
Thank you in advance!