Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

separate styles for separate module in Angular 5

My project has two main parts. One for public web pages and the other for admin control panel. Each of them has separate CSS and javascript files for their template.

If I define all CSS and js files in index.html, all files load in the first meet of the web page, and also maybe have a conflict between CSS classes.

How can I handle this problem?

app.component:

<router-outlet></router-outlet>

app-routing.module:

import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";

import { FirstComponent } from './first/first.component';


const appRoutes: Routes = [
  { path: 'first', component: FirstComponent },
  {
    path: 'controlpanel',
    loadChildren: 'app/control-panel/control-panel.module#ControlPanelModule'
  },
  {
    path: 'publicpanel',
    loadChildren: 'app/public-panel/public-panel.module#PublicPanelModule'
  }
];

each module has its submodules. Can I separate their styles?

like image 277
Mohammad Ali Avatar asked Nov 07 '25 09:11

Mohammad Ali


1 Answers

Use sass and create a class flag for public and admin components like this

theme/_public.scss

.public{ 
  label { 
    color:red;
  }
}

theme/_admin.scss

.admin { 
  label {
    color:green;
  }
}

and this in main style.scc

@import "theme/_public.scss";
@import "theme/_admin.scss";

this is much better for app performance you will have one style file with public and admin pages style

stackblitz example

like image 71
Muhammed Albarmavi Avatar answered Nov 09 '25 21:11

Muhammed Albarmavi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!