How to save CSS class to Ionic Storage on click?


How I can set css class to storage on click and then how I’ll get it?

Let me explain it to you more:
When user will click on button “24” then a class “fontSize24” is added to the content and when user clicks on button “30” then class “fontSize30” is added to the content and “fontSize24” is removed. How do I can save it to storage?

Code is given below:


      <button (click)="fontSizeOne()">24</button>
<button (click)="fontSizeTwo()">30</button>


fontSizeOne(direction: string) { = direction;

fontSizeTwo(direction: string) { = direction;

Best Regards

Anyone there to reply?

Use ngStyle or ngClass.

How I can use this in my scenario?

If you look at the official docs for ngClass and ngStyle, you will see code examples.

I’m beginner so it is difficult for me to understand it without any example


maybe this helps.



Best regards, anna-liebt

The links being provided have the code examples you’re asking for

@anna_liebt @jaydz

Yes these links help to set Classes and Styles but it doesn’t help them that how store class in Ionic Storage or localStorage.

maybe I understood you wrong.

This is how you change dynamically css with a click.
The css itselfs comes from a scss. Variables are in .ts.

Why you want store it, when every thing is written in a .scss or .ts file.?

Otherwise look to storage documentation.

Best regards, anna-liebt

Actually on a user click, I’m adding a class to html content and I want to store that class in the storage.

Best Regards

Any other solution for this issue?


that part I understood, what didn’t understood why you want do that.

Take a look to storage documentation or make a search in forum with keyword storage.
Or …
Bset regards, anna-liebt

Thanks! I hope this will help me to resolve the issue.