AngularJs 通过 ocLazyLoad 实现动态(懒)加载模块和依赖
好了,现进入正题,在 AngularJs 实现动态(懒)加载主要是依赖于3个主JS文件和一段依赖的脚本。
实现的过程主要是引用3个主要的JS文件
- <script src="angular/1.4.8/angular/angular.min.js"></script>
- <script src="angular/ui-router/release/angular-ui-router.min.js"></script>
- <script src="angular/oclazyload/src/ocLazyLoad.min.js"></script>
然后通过 APP 配置,将依赖的脚本进行注入操作
- var app = angular.module('pkcms', ["ui.router", "oc.lazyLoad"]);
- app.config(["$provide", "$compileProvider", "$controllerProvider", "$filterProvider",
- function ($provide, $compileProvider, $controllerProvider, $filterProvider) {
- app.controller = $controllerProvider.register;
- app.directive = $compileProvider.directive;
- app.filter = $filterProvider.register;
- app.factory = $provide.factory;
- app.service = $provide.service;
- app.constant = $provide.constant;
- }]);
- // 按模块化加载其他的脚本文件
- app.constant('Modules_Config', [
- {
- name: 'treeControl',
- serie: true,
- files: [
- "Scripts/angular-bootstrap/ui-bootstrap-tpls-0.14.3.min.js"
- ]
- }
- ]);
- app.config(["$ocLazyLoadProvider","Modules_Config",routeFn]);
- function routeFn($ocLazyLoadProvider,Modules_Config){
- $ocLazyLoadProvider.config({
- debug:false,
- events:false,
- modules:Modules_Config
- });
- };
以上是初始化动态加载的配置过程。
接着是建立路由
- "use strict"
- app.config(["$stateProvider","$urlRouterProvider",routeFn]);
- function routeFn($stateProvider,$urlRouterProvider){
- $urlRouterProvider.otherwise("/main");
- $stateProvider
- .state("main",{
- url:"/main",
- templateUrl:"views/main.html",
- controller:"mainCtrl",
- controllerAs:"main",
- resolve:{
- deps:["$ocLazyLoad",function($ocLazyLoad){
- return $ocLazyLoad.load("controllers/main.js");
- }]
- }
- })
- .state("adminUser",{
- url:"/adminUser",
- templateUrl:"views/adminUser.html",
- controller:"adminUserCtrl",
- controllerAs:"adminUser",
- resolve:{
- deps:["$ocLazyLoad",function($ocLazyLoad){
- return $ocLazyLoad.load("controllers/adminUser.js");
- }]
- }
- })
- };
最后是按路由配置的在对应目录下建2个HTML页面文件和2个JS文件用做测试
main.html
- <div>
- {{main.value}}
- </div>
adminUser.html
- <div>
- {{adminUser.value}}
- </div>
main.js
- /**
- * mainCtrl
- * Created by pkcms.cn on 2016/6/24.
- */
- (function () {
- "use strict"
- app.controller("mainCtrl", mainCtrlFn);
- function mainCtrlFn() {
- this.value = "Hello World";
- }
- }())
adminUser.js
- /**
- * adminUserCtrlFn
- * Created by pkcms.cn on 2016/6/24.
- */
- (function () {
- app.controller('adminUserCtrl',adminUserCtrlFn);
- function adminUserCtrlFn() {
- this.value = "welcome to admin user";
- }
- }());
github url :https://github.com/366065186/angularjs-oclazyload
转载请注明:PKCMS博客 » AngularJs 通过 ocLazyLoad 实现动态(懒)加载模块和依赖
AngularJs 通过 ocLazyLoad 实现动态(懒)加载模块和依赖的更多相关文章
- AngularJs 通过 ocLazyLoad 实现动态(懒)加载模块和依赖-转
http://blog.csdn.net/zhangh8627/article/details/51752872 AngularJs 通过 ocLazyLoad 实现动态(懒)加载模块和依赖 标签: ...
- AngularJs 动态加载模块和依赖
最近项目比较忙额,白天要上班,晚上回来还需要做Angular知识点的ppt给同事,毕竟年底要辞职了,项目的后续开发还是需要有人接手的,所以就占用了晚上学习的时间.本来一直不打算写这些第三方插件的学习笔 ...
- Angular ui-roter 和AngularJS 通过 ocLazyLoad 实现动态(懒)加载模块和依赖
什么是ui-router ui-router是AngularUI库最有用的组件之一(AngularUI库由AngularJS社区构建).它是一个第三方路由框架,允许通过状态机制组织接口,而不是简单的U ...
- angular5给懒加载模块添加loading
在根组件的构造函数中直接执行: this.router.events.subscribe(event=>{ if(event instanceof RouteConfigLoadEnd) { t ...
- Angular中懒加载一个模块并动态创建显示该模块下声明的组件
angular中支持可以通过路由来懒加载某些页面模块已达到减少首屏尺寸, 提高首屏加载速度的目的. 但是这种通过路由的方式有时候是无法满足需求的. 比如, 点击一个按钮后显示一行工具栏, 这个工具栏组 ...
- webpack多页面开发与懒加载hash解决方案
之前讨论了webpack的hash与chunkhash的区别以及各自的应用场景,如果是常规单页面应用的话,上篇文章提供的方案是没有问题的.但是前端项目复杂多变,应对复杂多页面项目时,我们不得不继续踩w ...
- 在webpack中使用Code Splitting--代码分割来实现vue中的懒加载
当Vue应用程序越来越大,使用Webpack的代码分割来懒加载组件,路由或者Vuex模块, 只有在需要时候才加载代码. 我们可以在Vue应用程序中在三个不同层级应用懒加载和代码分割: 组件,也称为异步 ...
- 18-Angular 自定义模块以及配置路由模块懒加载
新建项目,新建几个子模块,实现懒加载 用户.商品.文章 新建这三个模块 创建模块的时候后面加 --routing.会自动生成模块的路由文件 先删掉. 重新创建模块带routing 这样就会生成两个文件 ...
- ionic3 懒加载在微信上缓存的问题
1.懒加载是什么? 在ionic2中所有的组件.模块.服务.管道等都堆积在app.module.ts模块中,在页面初始化的时候会一次性加载所有的资源,导致资源过大,页面渲染缓慢,也导致app.modu ...
随机推荐
- Sensitive directory/file Integrity Monitoring and Checking
catalogue . OSSEC . HashSentry: Host-Based IDS in Python . Afick . 检测流程 1. OSSEC OSSEC is an Open So ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- sql语句,order by
ORDER BY子句必须出现在SELECT中的最后一个子句. 在排序的列中NULL值被认为是最大的. 在SQL语句中给表达式定义别名是一个好习惯. 多列排序时不管升序还是降序,每个列需要单独设置
- 练习用基础SQL语句
http://www.cnblogs.com/zxlovenet/p/3728842.html 本文语句大部分SQL语句来自<数据库系统概论>(第四版)王珊&萨师煊 ,是我们上课用 ...
- selenium 打开浏览器
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebE ...
- 换行的css属性
//正常换行 word-break:keep-all;word-wrap:normal; //下面这行是自动换行 word-break:break-all;word-wrap:break-word ...
- ThinkPHP Where 条件中使用表达式
本文转自:这里 Where 条件表达式格式为: $map['字段名'] = array('表达式', '操作条件'); 其中 $map 是一个普通的数组变量,可以根据自己需求而命名.上述格式中的表达式 ...
- System.Web.HttpRequestValidationException: A potentially dangerous Request.F
ASP.NET .0验证请求 System.Web.HttpRequestValidationException: A potentially dangerous Request.F System.W ...
- V4L2框架分析学习一
转载于http://www.techbulo.com/1193.html 1.概述 Video4Linux2是Linux内核中关于视频设备的内核驱动框架,为上层的访问底层的视频设备提供了统一的接口.凡 ...
- 转载:Centos7 从零编译配置Memcached
序言 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度. Memca ...