css - Angular 5中单独模块的单独样式

标签 css angular module bootstrap-4

我的元素有两个主要部分。一个用于公共(public)网页,另一个用于管理控制面板。他们每个人的模板都有单独的 CSS 和 javascript 文件。

如果我在 index.html 中定义所有的 CSS 和 js 文件,所有文件都会在网页的第一次见面时加载,并且 CSS 类之间也可能会发生冲突。

我该如何处理这个问题?

应用程序组件:

<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'
  }
];

每个模块都有它的子模块。我可以将它们的样式分开吗?

最佳答案

使用 sass 并为公共(public)和管理组件创建一个类标志 像这样

主题/_public.scss

.public{ 
  label { 
    color:red;
  }
}

主题/_admin.scss

.admin { 
  label {
    color:green;
  }
}

这在 main style.scc 中

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

这对于应用程序性能来说要好得多你将拥有一个包含公共(public)页面和管理页面样式的样式文件

stackblitz example

关于css - Angular 5中单独模块的单独样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51360813/

相关文章:

javascript - 尝试使用 Javascript/CSS 更改属性,但无法使其在 if/else 语句中工作?

html - 如何在 Angular 形 Material 中居中垫卡?

php - 使用 Phalcon PHP 框架的嵌套多模块应用程序?

Python,关于分组函数的建议

c# - ASP.NET 样板插件模块或动态模块

css - 构造我想要的简单 HTML 布局的最佳方式

javascript - jQuery/Javascript 函数在 Chrome 中有效,但在 IE11 中无效

css - Internet Explorer 中的 Google 字体 Flash

menu - 禁用侧面菜单的滑动以打开 Ionic 2 中登录页面(或任何页面)的手势

typescript - Angular 2 *ngIf 不重新评估模型更改