对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 ...
随机推荐
- 六、通过插件如何创建自己的MEL command
1. MAYA API支持不同类型的plugin (1)Command Plugin——扩充MEL命令 (2)Tool Commands——通过鼠标输出 (3)DG plugin——对场景添加新的操作 ...
- JS和CSS关于大小写的区分
方法: document.getElementById("xx").style.xxx中的所有属性是什么 盒子标签和属性对照 CSS语法(不区分大小写) JavaScript语法( ...
- ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='
多表查询出错,貌似是编码问题. 我比较的两个表的某个字段,设为查询条件,两个字段等于某个值,参照网上的某些论坛调用alter语句,但是依旧没有效果.最后直接拆分成两个条件,a.字段1=x值,b.字段2 ...
- 关于thinkphp 中的字段自动检查机制
在thinkphp中有很好用的自动检查机制$_validate() 但是必须与create接收配合使用 可以很方便的帮助我们去判断 namespace Home\Model;use Think\Mod ...
- windows下Redis编译安装
redis是现在比较流行的noSQL,主流大型网站都用的比较多,很多同学不知道怎么安装,这里介绍在windows下面安装以及扩展,提供学习使用,实际使用环境多在Linux下. 首先到相应网站下载red ...
- django中的静态文件管理
一个站点通常需要保存额外的文件,比如图片 css样式文件 js脚本文件 ,在django中,倾向于将这些文件称为 静态文件.django提供了django.contrib.staticfile ...
- HTML <!DOCTYPE> Declaration
<!DOCTYPE html><html><head><title>Title of the document</title></he ...
- 详解log4j2(下) - Async/MongoDB/Flume Appender 按日志级别区分文件输出
1. 按日志级别区分文件输出 有些人习惯按日志信息级别输出到不同名称的文件中,如info.log,error.log,warn.log等,在log4j2中可通过配置Filters来实现. 假定需求是把 ...
- JAXB 2.0 API is being loaded from the bootstrap classloader
在使用webservice,mule esb等需要jaxb的项目里经常会出现 JAXB 2.0 API is being loaded from the bootstrap classloader这个 ...
- VS&SQL StartUp Crash - CLR20R3
VS2013和SQL Management Studio 在启动时直接崩溃,错误提示CLR20R3,问题签名4是windowsbase, 这说明是操作系统的问题导致启动崩溃,在网上找到一些解决方案: ...