Angular学习:模块和组件的动态加载
来源:互联网 发布:中国软件企业排名 编辑:程序博客网 时间:2024/06/16 12:58
可以利用路由的loadChildren来动态加载angular模块和组件。
1. 建立一个要动态加载的模块(包含相应的组件)
dyn-plugin.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DynPluginRoutingModule } from './pfc-plugin-routing.module';
import { DynPluginComponent } from './pfc-plugin.component';
@NgModule({
imports: [
CommonModule,
DynPluginRoutingModule
],
declarations: [DynPluginComponent],
exports: [DynPluginComponent]
})
export default class DynPluginModule { }
注意:要有default 。
组件的代码就省略了。
2. 通过路由的loadChildren来动态加载模块。
guimain-routing.module.ts
let baseRoute: Route = {
path: '',
component: GuimainComponent,
children: [
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full'
},
{
path: 'config',
component: MainconfigComponent
},
{
path: 'dashboard',
component: DashboardComponent
}
]
}
let appendRoute: Route = {
path: '',
component: GuimainComponent,
children: [
{
path: 'plugin',
loadChildren: 'app/plugin/dyn-plugin/dyn-plugin.module'
}
]
}
let rtnRoutes: Routes = [baseRoute, appendRoute];
@NgModule({
imports: [
RouterModule.forChild(rtnRoutes)
],
exports: [RouterModule]
})
export class GuimainRoutingModule { }
- Angular学习:模块和组件的动态加载
- angular中模块的自动加载和手动加载
- AngularJS学习:Angular的模块
- Angular tab标签页动态加载组件具体实现
- angular使用requirejs/ui-router/angularAMD实现动态加载模块
- angular模块加载
- linux驱动模块的动态加载和静态加载
- angular 动态组件
- Apache模块动态加载和静态加载
- Apache模块动态加载和静态加载
- Apache模块动态加载和静态加载
- Apache模块动态加载和静态加载
- 第14篇:angular动态添加和删除组件元素的封装函数
- Loader组件的动态加载
- (六)使用angular.bootstrap完成模块的手动加载
- 使用angular.bootstrap完成模块的手动加载
- 使用angular.bootstrap完成模块的手动加载
- eCos模块动态加载支持——objloader组件
- 使用gdb进行调试
- DS18B20 单总线多器件的ROM 搜索, ALARM 检测, CRC 校验 源码实现, 基于 STM32F103
- js数组去重的三种常用方法总结
- 【Linux网络编程】基于TCP协议 I/O多路转接(select) 的高性能回显服务器客户端模型
- centos7配置hadoop伪分布式
- Angular学习:模块和组件的动态加载
- win7系统右键怎么添加管理员权限?
- url中的参数带有&连接符号处理 url参数带路径问题
- 如何给Myeclipse设置个性化的代码注释模板?
- Service(二)
- GCC 参数详解
- <第一章>Python环境配置
- xml
- JAVA 缓存数组之----ByteArrayInputStream类详解