【翻译】oc.lazyLoad with Angular ui router(按需加载文件)
2015-12-14 12:11
841 查看
我们的想法是当我们点击按钮改变ui路由器同时,我们加载使用oc.lazyLoad js文件和模板。
看下面的例子:
index.html
app.js
store.js
store.tmpl.html
原文链接-->(http://www.cnblogs.com/Answer1215/p/4039374.html)
看下面的例子:
index.html
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body ng-app="app" ng-controller="AppCtrl as vm"> <button ng-click="vm.click()">Click Me</button> <ui-view></ui-view> <script src="bower_components/angular/angular.min.js"></script> <script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script> <script src="bower_components/oclazyload/dist/ocLazyLoad.min.js"></script> <script src="app.js"></script> </body> </html>
app.js
angular.module('app',["ui.router", "oc.lazyLoad"]) .config(function($stateProvider){ $stateProvider.state('store', { templateUrl: 'store/store.tmpl.html', controller: 'StoreCtrl as store', resolve: { store: function($ocLazyLoad){ return $ocLazyLoad.load( { name: "store", //module name is "store" files: ["store/store.js"] } ) } } } ) }) .controller("AppCtrl", function($state){ var app = this; app.click = function(){ $state.go('store'); } })
store.js
angular.module("store", []) .controller("StoreCtrl", function(){ var cart = this; cart.message = "I'm a message from the controller"; })
store.tmpl.html
<div> <h1>Here we have manyy thing to load!</h1> {{store.message}} </div>
原文链接-->(http://www.cnblogs.com/Answer1215/p/4039374.html)
相关文章推荐
- Git GUI下载远程源代码简单使用介绍
- Shiro介绍(六):扩展自己的@RequiresPermission
- 利用WebRequest类上传文件
- [Tue, 1 Dec 2015 ~ Fri, 4 Dec 2015] Deep Learning in arxiv
- UI之slider、segmentControl
- mysql_query 发送Select 语句
- Your build settings specify a provisioning profile with the UUID, no provisioning profile was found
- 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
- 并发队列ConcurrentLinkedQueue和阻塞队列LinkedBlockingQueue用法
- duilib中ListCtrl控件的实现
- kali攻防第10章 Burp Suite功能的简单介绍
- duilib CTileLayoutUI 控件
- H-UI的前端处理验证,判断是否已经存在,比较健全的模板,可以自己添加一些校验
- mysql_query()函数 向MYSQL服务器引擎发送insert语句 update语句 delete 语句
- duilib : 模态窗口
- UI之gestureRecognizer
- This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recomme
- 旋转进度--UiActivityIndicatorView
- UIScrollView 基本使用 和 循环播放(NSTimer)
- android UI进阶之实现listview中checkbox的多选与记录