angularangular-cliangular-components

Using styleUrls instead of styleUrl in component Angular 17


How to set styleUrls instead of styleUrl in component by command ng generate component? In Angular 14, styleUrls property in the component decorator was set automatically after component generating. In Angular 17, is styleUrl. How to change it?

I can manually edit the component file after generating it to change styleUrl to styleUrls, but it's not okay.


Solution

  • Angular 17 has introduced styleUrl as a convenience for cases where there's only one stylesheet. If you need to use multiple stylesheets and prefer the styleUrls property, as of now, there is no built-in command option in Angular CLI to automatically set styleUrls instead of styleUrl during component generation.

    You either have to manually edit the component files or consider creating a custom schematic.

    Source code