对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 ...
随机推荐
- Consuming a Web Service in AX 2012
Consuming a Web Service in AX 2012 在AX2012版本中如果想调用外部的Web Service变得非常容易. 第一步,在VS中创建一个Web Service并发布 第 ...
- TortoiseSVN 版本回滚
尝试用TortoiseSVN进行版本回滚,回滚到的版本和实际的内容有出入,可能是点了太多次给点乱了,囧~ 不过发现一个比较靠谱的方法,如下: 右键点击文件TortoiseSVN->showlog ...
- iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】
在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...
- MFC使用TRACKMOUSEEVENT触发mouseHover和mouseLeave
为对话框添加WM_MOUSEHOVER或WM_MOUSELEAVE消息并不会响应.MFC需要特殊处理,其中一法就是使用TRACKMOUSEEVENT void CmfcDlgDlg::OnMouseM ...
- XML操作总结
在开发过程中对XML的使用不是太多,要用到时候也是想办法绕过去,最近一个同事给了一个详细的操作.分享一下 using System; using System.Collections.Generic; ...
- ubuntu 开机显示错误:无法应用原保存的显示器配置
无法应用原保存的显示器配置CRTC 63:尝试 800x600@60Hz 模式输出在 1366x768@60Hz (通过 0)CRTC 63:尝试 2560x1600@60Hz 模式输出在 1366x ...
- SPI线协议详解
更多的内容可以参考 https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI的工作模式: CPOL.CPHA的搭配可以有四种工 ...
- logging日志模块
为什么要做日志: 审计跟踪:但错误发生时,你需要清除知道该如何处理,通过对日志跟踪,你可以获取该错误发生的具体环境,你需要确切知道什么是什么引起该错误,什么对该错误不会造成影响. 跟踪应用的警告和错误 ...
- 28、跟我来一起精通echarts吧
1.折线图 option = { title : { text: '未来一周气温变化', subtext: '纯属虚构' }, tooltip : { trigger: 'axis' }, legen ...
- Ubuntu-12.04-server 配置修改静态 IP地址
前几天在装Ubuntu 12.04 Server版系统的服务器时IP地址写错了,导致服务器不能上网,今天重新修改了一下IP地址,这里做一个总结. 1.配置静态IP地址 sudo vi /etc/net ...