What is happening here ? Angular uses the component metaphore, each component has its own view encapsulation. Which is emulated by default (see below for meaning).
You can switch to another ViewEncapsulation
mode by setting the encapsulation property to one of these values :
ViewEncapsulation.None
: No encapsulation is done, your component style will apply to any element matching the selector used in the CSS.
ViewEncapsulation.Emulated
: Angular will rewrite your components styles (adding custom attributes to selectors) to match only the related component and append an inline <style>
tag n the head
.
ViewEncapsulation.Native
: Angular will use the native shadow DOM of the browser (won't work on old browsers).
example :
@Component({
...
encapsulation: ViewEncapsulation.Native,
...
})
see Component Styles for more details.
To conclude :
You can avoid the evaluation on the fly, by putting your styles in a random css file that you puth in the head
of the HTML, but it will end up of every components styles not being encapsulated.
Maybe the ViewEncapsulation.Native
is more performant, but I have no proof for this neither and idea on how to benchmark it ( there is a question related to this topic), and it does not work with older browsers.