我有一个应用程序,在这个应用程序中,我必须为动态主题实现配置和使用更少的内容。问题是,我们没有使用角-cli,配置在这里有点奇怪,所以我们手动引导角模块。
以下是app的配置:
package.json
"dependencies": {
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"@angular/upgrade": "^4.0.0",
"@angular/animations": "^4.0.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "^5.0.1",
"systemjs": "0.19.39",
"zone.js": "^0.8.4"
},
and so on..main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
import { ThemeModule } from "./theme.module";
window.appnamespace.platform = platformBrowserDynamic();
window.appnamespace.AppModule = AppModule
window.appnamespace.ThemeModule = ThemeModule;theme.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { ThemeComponent } from "./theme.component";
import { ThemeToolbar } from "./Themes/theme-toolbar/theme-toolbar.component";
import { ThemePreview } from "./Themes/theme-preview/theme-preview.component";
import { ThemeService } from "./services/themeManagement.service";
const PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
suppressScrollX: true
};
@NgModule({
imports: [
BrowserModule,
],
declarations: [
ThemeComponent,
ThemeToolbar,
ThemePreview,
SetFocusDirective
],
providers: [ThemeService, LocalizeThemeService, CommonService],
bootstrap: [ThemeComponent]
})
export class ThemeModule { }its组件:
@Component({
selector: "my-theme",
templateUrl: "../js/divdrawer/Themes/theme.template.html"
})
export class ThemeComponent implements OnInit {
//
}并通过javascript引导它,如: window.appnamespace.platform.bootstrapModule(window.appnamespace.ThemeModule);:
theme.preview组件
@Component({
selector: "theme-preview",
templateUrl: "../theme-preview/theme-preview.component.template.html",
styleUrls: ['../theme-preview/theme-style.less']
})
export class ThemePreview implements OnInit {
// some code
}theme-style.less:包含css
@import "./theme-variable.less";
// some csstheme-variable.less:包含较少的变量
@header-bg :red;
@badge-title-bg : #ddd;我希望在主题预览组件中使用较少的变量和样式来动态更改主题。
如何仅在主题组件中配置更少的内容。
发布于 2019-10-25 11:08:17
在您的@Component中,属性styleUrl拥有所有需要合并到一个CSS文件中的样式文件。然而,这是由角CLI完成的。
如果您打算使用CLI从less生成CSS,请转到名为angular.json的文件,并将schematics.@schematics/angular:component.style的值更改为'less'。
然而,这可能无助于动态(运行时)主题化。动态主题化,
@import语句在任何一个主文件node.js server和less.js编译它。因此,less.js将是您的node.js项目中的生产依赖项。<link href="main.less" rel="stylesheet" type="text/less"/>下一步,将less.js导入到角应用程序的main.ts中,或者在HTML中为less.js使用脚本标记。在@Component中,可以删除styleUrls,因为它没有使用。
此外,所有与组件相关的样式都需要包装在一个特定于组件的类中(包括HTML和更少)。这将确保您实现与角CLI相同的行为。
希望这能有所帮助。如有任何更具体的问题,请评论。
https://stackoverflow.com/questions/58351135
复制相似问题