Quick method to alter theme and store it - Ionic

How can I modify the appearance of an element by changing its color and font size when a user clicks a button?

<h1> Hello Stackoverflow </h1>
<button (click)="changeTheme()">Change Theme</button>

What is the best approach to change the theme and store it so that the changes persist when the user reopens the app in an Ionic application?

I have multiple pages and need to adjust their font size and color as well.

Answer №1

There are a variety of options to store data in the browser, such as localStorage here, sessionStorage, cookies, etc.

To use LocalStorage, simply set the key and value for the item you want:

window.localStorage.setItem('themeColor', '#your color value or theme name');

You can retrieve it like this:

const storedColor = window.localStorage.getItem('themeColor');

And delete it using:

window.localStorage.removeItem('themeColor')

If you need more advanced features, consider using localForage.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue: Trying to emit before Angular Webpack plugin has been initialized (Error: Emit attempted before Angular Webpack plugin initialization)

Currently, I am working on a project in Angular 15 where I am migrating code from Angular version 5. Despite fixing all the errors, I'm facing one particular issue. Here are the details of my current Angular version: Angular CLI: 15.2.10 Node: 18.18. ...

Retrieve the name from the accordion that was clicked

Hey there, I have a simple accordion that is based on an API called "names". <div *ngFor="let item of showDirNames | async | filter: name; let i = index;"> <button class="accordion" (click)="toggleAccordian($event, i)&q ...

The DatePicker in Angular2 and Typescript is unable to execute the property 'toggle' because it is undefined

I've encountered an issue with the calendar icon for angular2's datepicker. Whenever I try to click on it, I keep getting this error: TypeError: Cannot read property 'toggle' of undefined at Object.eval [as handleEvent] (Admiss ...

Issue encountered with Vue.js build configuration not being loaded while running on the build test server

I am working on a Vue 2 project and facing an issue with loading configuration settings from a config.json file. My router\index.ts file has the line: Vue.prototype.$config = require('/public/config.json') The config.json file contains imp ...

Prettyprint XML in Angular 8+ without using any external libraries

I am working with Angular 8+ and I need to display XML content in a nicely formatted way on my HTML page. The data is coming from the backend (Java) as a string, and I would like to present it in its XML format without relying on any external libraries or ...

Receiving contextual information from Microsoft Teams within an Angular application integrated as a tab

I am currently integrating an Angular website into a Microsoft Teams tab. In order to perform certain computations, I need to retrieve the Team ID. To achieve this, I have recently added npm install --save @microsoft/teams-js. Below is the code snippet th ...

Issue with Angular 7 cli failing to recognize a custom TypeScript file

While working on an Angular 7 component, I encountered an issue when trying to read a custom file. The problem arises when the server restarts, even though there are no errors in the component's TypeScript file. ERROR: app/zontify-components/zonti ...

How to implement and utilize a history-object interface in React with Typescript?

Can you help me with setting up an interface for a history object in my component? Currently, it is typed as any and I want to type it appropriately. Object: https://i.sstatic.net/Sru8R.png Here's the code snippet: import React, { useState } from &a ...

Creating a service instance within the constructor in Angular 2

I'm new to Angular 2 and Typescript and I'm trying to wrap my head around DI. One thing that has been tripping me up is the way variables referring to a service are typed into the constructor in all the code examples I've come across. Why is ...

Implementing Node.js microservices with AWS Cognito leveraging Amplify's best practices

I am currently working on developing a Node.js API that is broken down into several small APIs (microservices) communicating with each other through requests and responses. Additionally, I am utilizing Angular for the frontend. My next step is to enhance ...

Is it possible to utilize both $uibModal and $uibModalInstance within the same controller to create a modal popup in an Angular project incorporating TypeScript?

Being new to Angular with Typescript, I encountered an issue while trying to implement a modal popup in Angular. The problem arises when I have a dropdown menu that triggers the opening of a modal popup with two buttons, "Yes" and "No". To handle this, I h ...

Setting a maximum limit for selections in MUI Autocomplete

Code updated to display the complete script logic. I want to restrict the number of selections based on a value retrieved from the database, but in this example, I have set it to 3 manually. The error message I'm encountering is "Cannot read properti ...

Using Angular to Pass REST Data from Service to Component

Can someone assist me in troubleshooting why my data is not showing up in the HTML? I have checked everything but still can't seem to figure it out. Also, I apologize if I missed any important details and I am willing to provide them. Here are the co ...

Tips for retrieving and presenting information from a JSON document in a React TypeScript application

I am struggling to display data in a list format using TypeScript. I am able to fetch the data but unable to display it properly. I am currently using map to iterate through an array of JSON objects. //json file [ { "id": "6s", ...

Can you explain the significance of the additional pipeline in the type declaration in TypeScript?

Just recently, I defined a type as follows- interface SomeType { property: { a: number; b: string; } | undefined; } However, upon saving the type, vscode (or maybe prettier) changes it to- interface SomeType { property: | { a: nu ...

IntersectionObserver activates prior to element's entrance into the viewport

I've set up a Vue component with the following structure: <template> <article> <!-- This content spans several viewport heights: you *have* to scroll to get to the bottom --> {{ content }} </article> <span ref ...

Angular 6 Universal does not pause for resolver completion

I recently completed the installation of Angular Universal start kit version 6 and designed my component within it. The main purpose of this component is to retrieve user information from an API upon loading and display it on the view. The issue I am faci ...

The attribute 'location' is not found in the 'File' data type

Recently, I made the switch from using multer to multer-s3 in my project. I have updated the controllers accordingly to store the "location" instead of the "filename". However, I am encountering a typescript error. At the moment, I am utilizing Localstack ...

Packaging an Angular project without the need for compiling

In order to enhance reusability, I structured my Angular 6 Project into multiple modules. These modules have a reference to a ui module that contains all the style sheets (SASS) as values such as: $primary-text-color: #dde7ff !default; Although this app ...

Issues with patching values in Angular 5 reactive forms when dealing with nested input fields

Currently, I am utilizing Angular 5 along with reactive forms. My form is being dynamically generated based on JSON data provided by the backend. While my structure works well with radio buttons, I encounter an issue when dealing with nested checkboxes at ...