[Ionic 4] Get primary color from code

How to get the Primary color in variables.css from code? [Ionic 4]

this one: --ion-color-primary: #008c8c;

i want to get this on typescript…

Thanksss

To get Sass variable from TypeScript code I use this javascript code.

getComputedStyle(document.documentElement).getPropertyValue('--ion-color-secondary')

Example

const my_statusbar_color = getComputedStyle(document.documentElement).getPropertyValue('--ion-color-secondary');
StatusBar.setBackgroundColor({ color: my_statusbar_color })
StatusBar.show();

I hope I’ve helped

6 Likes

Helped Me for ionic 5 too.

Thanks to bitti for this info. It was helpful in obtaining theme colors to use via TypeScript on an ionic 4 project I’m working on.