🎨 Should Angular Directives Have Styles?

Tom Smykowski
5 min readJul 22, 2024

A 7-year long debate about attribute directives and styles and Angular is still missing a feature. But this can change

As usual I was browsing issues reported in Angular and stumbled upon an interesting discussion that started in 2017. 7 years ago.

I’ll brief you in into the topic, because the discussion is quite long and it’s actually hard to grasp the main issue at hand.

This article was brought to you thanks to my readers

In short there is a large demand from Angular developers to be able to define styles and styleUrl for directives.

Let’s break it down. Angular applications are built mainly with components and composition.

It means you build components that encapsulate behaviour and look of a feature. For example a button. Then, you can compose user interface with that button, not caring anymore about it’s internal implementation and styling.

The look and partially behaviour is achieved with CSS (or SCSS etc), a style sheet defined internally in styles attribute of the @Component directive or styleUrl. This attribute points to a CSS or SCSS file with styles.

Follow for more Angular articles!

--

--

Tom Smykowski

Software Engineer & Tech Editor. Top 2% on StackOverflow, 3mil views on Quora. Won Shattered Pixel Dungeon.