gpt4 book ai didi

css - 在一个 Angular 应用程序中动态切换两个 styles.css 文件

转载 作者:行者123 更新时间:2023-11-27 23:40:18 25 4
gpt4 key购买 nike

我必须将两个 Angular 应用程序合并到一个主要的 Angular 应用程序中。因此,现在我在一个 Angular 应用程序中有两个 styles.css 文件。在合并两者后运行此应用程序时,css 将完全用于 Angular 应用程序。

有什么方法可以根据需要动态调用这两个style.css文件吗?或者我需要逐一检查每个类(class)?

最佳答案

我建议你使用两种不同的布局,每一种都是一个组件,所以每一种都有不同的一组样式。使用 Angular 路由器真的很容易。

在你的路由模块中:

// Layout 1
{
path: '',
component: Layout1Component,
children: [
{ path: 'pageL1_1', component: PageL1_1Component },
{ path: 'pageL1_2', component: PageL1_2Component }
]
},

// Layout 2 routes goes here here
{
path: '',
component: Layout2Component,
children: [
{ path: 'pageL2_1', component: PageL2_1Component },
{ path: 'pageL2_2', component: PageL2_2Component }
]
},

在你的 app.component.html 中:

<router-outlet></router-outlet>

布局模板必须包含元素以显示子导航组件。

重要:每个 layput Controller 都应禁用 View 封装,以便样式应用于子组件:

@Component({
selector: 'app-layout_1',
templateUrl: './layout_1.component.html',
styleUrls: ['./layout_1.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class Layout1Component implements OnInit {
...
}

关于css - 在一个 Angular 应用程序中动态切换两个 styles.css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57069248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com