对angular实现延迟加载template和controller
1、在lib目录中添加 script.js 文件,并在index.html其他<script>之前引用之:
<script src="lib/script.js"></script>
function LazyLoadTemplate(file) {
return function () {
return file;
}
}
function LazyLoadJs(file) {
return {
deps: function ($q, $rootScope) {
var d = $q.defer();
$script(file, function () {
$rootScope.$apply(function () {
d.resolve();
})
});
return d.promise;
}
}
}
var app = angular.module("app");
app.controllerProvider = $controllerProvider; // 主要是这个
app.compileProvider = $compileProvider; // 以下这两个备用
app.filterProvider = $filterProvider;
$stateProvider.state('page1', {
url: '/page1',
templateUrl: LazyLoadTemplate('page1.html'),
controller: 'Page1Ctrl',
resolve: LazyLoadJs("page1.js")
});
angular.module('app').controllerProvider.register("Page1Ctrl", function ($scope) {
$scope.title = "Page1";
});
<!--<script src="page1.js"></script>-->
对angular实现延迟加载template和controller的更多相关文章
- AngularJS 特性—SinglePage、template、Controller
单页Web应用(SinglePage) 顾名思义,只使用一个页面的Web应用程序.单页面应用是指用户通过浏览器加载独立的HTML页面,Ajax加载数据页面无刷新,实现操作各种操作. 模板(templa ...
- angular 自定义指令 link or controller
Before compilation? – Controller After compilation? – Link var app = angular.module('plunker', []); ...
- [Angular 2] Create template with Params
Angular 2 templates have a special let syntax that allows you to define and pass a context when they ...
- [Angular 2] Passing Template Input Values to Reducers
Angular 2 allows you to pass values from inputs simply by referencing them in the template and passi ...
- angular学习(四)-- Controller
1.4 控制器:Controller ng 中的控制器用来对 scope 进行操作 包括初始化数据和定义事件响应函数等 ng 用来解耦业务逻辑层和视图层的关键 controller 操作 scope, ...
- angular.js--demo2-----声明局部控制器controller
<!doctype html><html ng-app="HelloAngular"> <head> <meta charset=&quo ...
- angular ajax的使用及controller与service分层
一个简单的例子,控制层:.controller('publishController',['$scope','publishService', function($scope,publishServi ...
- [Angular 2] Share Template Content In Another Template With Content Projection <ng-content>
Angular 1 provided a mechanism to place content from your template inside of another template called ...
- [Angular] Test component template
Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...
随机推荐
- 【摘要】多线程 - BeginInvoke异步调用
private delegate int MyMethod(); private int method() { Thread.Sleep(); ; } private void MethodCompl ...
- 前端项目构建error
Refusing to install webpack as a dependency of itself 原因:package.json中,"name": "webpa ...
- [转载]:Fortran字符串的故事
一. Fortran 字符串与 C 字符串的区别 Fortran的字符串处理能力其实很弱,关于字符串的语法还很落后.它与 C 字符串最大的区别就是:Fortran字符串是固定长度的,没有 \0 结束 ...
- VHDL 学习
近期在接触 VHDL,首先要本好书,个人觉得 1)<VHDL for engineer> VHDL 大学实用教程 (这个名字翻译的无语...) 2)估计verilog的作者的 bhask ...
- 论velocity在不同后台语言下的不同
第一家公司使用asp.net开发的,本人从事前端工作.当时用velocity写模板程序记得也没配置啥,我就记得写了rewrite,html页面里头直接写的velocity. 现在公司用的java开发的 ...
- Python字典方法总结
1.清空字典中元素清空,dict变为{} L.clear()-> None. Remove all items from L 1 2 3 4 >>> L ={'shaw':2 ...
- SQL时间戳的使用
SQL时间戳的使用 一直对时间戳这个概念比较模糊,相信有很多朋友也都会误认为:时间戳是一个时间字段,每次增加数据时,填入当前的时间值.其实这误导了很多朋友. 1.基本概念 时间戳:数据库中自动生成的唯 ...
- [2015hdu多校联赛补题]hdu5372 Segment Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5372 题意:进行n次操作,操作分两种,0和1,每一个0操作按出现顺序有一个编号(从1开始 0操作 0 ...
- DrawerLayout学习,抽屉效果
第一节: 注意事项 *主视图一定要是DrawerLayout的第一子视图 *主视图宽度和高度匹配父视图,因为当你显示主视图时,要铺满整个屏幕,用户体验度较高 *必须显示指定的抽屉视图的android: ...
- poj 3841 Double Queue (AVL树入门)
/****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...