对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 ...
随机推荐
- BVT & BAT & SVT
1. BVT(Build Verification Test) a. BVT概念 Build Verification test is a set of tests run on every new ...
- [Jquery] Jquery AutoComplete的使用方法实例
jQuery的Autocomplete(自动完成.自动填充)插件 jquery-autocomplete配置: <script type="text/javascript" ...
- 【浅析】IMU代码
IMU的代码的引自https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/imumargalgo ...
- 【转载】C++ function、bind和lambda表达式
本篇随笔为转载,原贴地址:C++ function.bind和lambda表达式. 本文是C++0x系列的第四篇,主要是内容是C++0x中新增的lambda表达式, function对象和bind机制 ...
- 加密和ssl机制细节
1.1 背景知识 对称加密:加密解密使用同一密钥,加解密速度快.随着人数增多,密钥数量急增n(n-1)/2 非对称加密:使用公私钥配对加解密,速度慢.公钥是从私钥中提取出来的,一般拿对方公钥加密来保证 ...
- 关于 NPOI 报 Invalid column index (256). Allowable column range for BIFF8 is (0..255) or ('A'..'IV') 错误的解决办法
当看到这个错误的时候,网上搜索可以会有些说列数有限制之类的说法,这个说法是相对于 Office 2003 的,在 Office 2007 之前,最多只可以创建 列:在 Office 2007 之后, ...
- Rule of Modularity
As Brian Kernighan once observed, “Controlling complexity is the essence of computer programming.” . ...
- [转载] 1. JebAPI 之 jeb.api
本文转载自: https://www.zybuluo.com/oro-oro/note/142707 JEB API 官方地址:https://www.pnfsoftware.com/apidoc/ ...
- hibernate学习(设计一对一 关系 映射)
//主表 package org.crazy.app.domain; import javax.persistence.*; @Entity @Table(name="person_inf& ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...