I am a new bie to the world of angular so rite now I have developed the below program to load the themes dynamically as shown below
my-scss-file.scss :
@import '~@angular/material/core/theming/all-theme';
@include md-core();
$primary: md-palette($md-deep-purple);
$accent: md-palette($md-amber);
$theme: md-light-theme($primary, $accent);
@include angular-material-theme($theme);
.dark-theme {
$dark-p: md-palette($md-deep-purple, 700);
$dark-a: md-palette($md-amber);
$dark-t: md-dark-theme($dark-p, $dark-a);
@include angular-material-theme($dark-t);
}
my-html-file.html :
<div [class.dark-theme]="isDarkTheme">
<button (click)="toggleTheme()">Toggle theme</button>
my-ts-file.ts :
@Component({
selector: 'your-component-selector',
templateUrl: './my-html-file.html',
styleUrls: ['my-scss-file.scss']
})
export class YourComponent implements {
// by default, if you do not want the dark theme
private isDarkTheme = false;
constructor() { }
toggleTheme() {
this.isDarkTheme = !this.isDarkTheme;
}
}
now the output is like as shown below output of the above angular app
now my query is that along with these button i want to add images as shown below that will be shown along with button click
how the tentative image should be there
so for that i have added images folder in my project in which i have kept images now please advise where should i add the images url in my .scss file to achieve this
Images folder location in my workspace images folder location in my workspace
below is my .angular-cli.json file contents
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "dynamic-material-theming"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css",
"theme.scss"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}