dark mode in ionic5

 darkmode() {

const prefersColor = window.matchMedia('(prefers-color-scheme: dark)');
this.dark = prefersColor.matches;
this.updateDarkMode();

prefersColor.addEventListener(
'change',
mediaQuery => {
this.dark = mediaQuery.matches;
this.updateDarkMode();
}
);
}
updateDarkMode() {
this.dark = true;
// alert("data")
document.body.classList.toggle('dark', this.dark);
}

add functions in ngoninit of app.component.ts

Comments

Popular posts from this blog

how to split array as per fixed length, and ionic two dates differences in min,seconds,hours

How to Add Firebase Analytics to Your NativeScript Mobile App