angular - 如何从角度构建中排除模块?
问题描述
在我的角度应用程序中,有一堆模块。
我想从角度构建中排除几个模块。
例如:我有一个存储库,其中包含所有角度模块的完整代码,并且运行良好。一些模块是聊天模块,仪表板模块,产品模块,设备模块
- 场景1:我只想给一个客户聊天模块和产品模块
- 场景 2:我只想将仪表板模块和图表模块提供给另一个客户端。
我如何创建一个角度构建,以便它使用存储库,但根据客户端模块要求创建一个构建并从构建中排除不必要的模块?
解决方案
//app-module.ts
import { NgModule, Optional } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({}) class MyModule {}
// you can also put this config client-specific config
const client1 = true;
@NgModule({
imports: [ BrowserModule, client1 ? MyModule : []],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
constructor(@Optional() module: MyModule) {
console.log(module);
}
}
在延迟加载的情况下,包括基于条件的路由模块(未测试)
//app-module.ts
const client1 = true;
let GlobalRoutingModule
if (client1) {
import('./app-routing-client1.module')
.then((routingModule) => {
GlobalRoutingModule = routingModule
});
} else {
import('./app-routing-client2.module')
.then((routingModule) => {
GlobalRoutingModule = routingModule
});
}
推荐阅读
- node.js - Nodejs + Typescript:如何用模型定义响应结构
- python - Python - 添加到数据框的现有行
- unix - RAM 中的虚拟内存和页面
- php - 警告:preg_replace_callback():需要参数 2, 'str_replace(array('.', ',', "'", ' '), '', '\1') 。'.\4'',作为一个有效的回调
- c# - MVVM Combobox 绑定:从/向更多源设置和获取数据
- jquery - Jquery:如何自动将 window.location.hash 应用为与按钮 ID 相同的数字?
- r - r中的散点图具有巨大的独特观察
- datatables - 输入类型搜索清除按钮 Microsoft Edge 无法与数据表一起正常工作
- matlab - 在 Simulink 中以特定时间速率测量信号
- python - 如何打破python中的while循环?