Mastering Web Application Development with AngularJS 读书笔记(三)
第一章笔记 (三)
一、Factories
factory 方法是创建对象的另一种方式,与service相比更灵活,因为可以注册可任何任意对象创造功能。例如:
myMod.factory('notificationsService',function(notificationsArchive){
var MAX_LEN = 10;
var notifications = [];
return {
push:function (notification) {
var notificationToArchive;
var newLen = notifications.unshift(notification);
//push 方法现在依赖闭包了
if (newLen > MAX_LEN) {
notificationToArchive = this.notifications.pop();
notificationsArchive.archive(notificationToArchive);
}
},
// other methods of the NotificationsService
};
二、常量 Constants
myMod.provider('notificationsService', function () {
var config = {
maxLen : 10
};
var notifications = [];
return {
setMaxLen : function(maxLen) {
config.maxLen = maxLen || config.maxLen;
},
$get : function(notificationsArchive) {
return {
push:function (notification) {
…
if (newLen > config.maxLen) {
…
}
},
// other methods go here
}
};
});
六、运行阶段

angular.module('app', ['engines']) .factory('car', function ($log, dieselEngine) {
return {
start: function() {
$log.info('Starting ' + dieselEngine.type);
};
}
});
angular.module('engines', []) .factory('diesel1Engine', function () {
return {
type: 'diesel'
};
});
Mastering Web Application Development with AngularJS 读书笔记(三)的更多相关文章
- Mastering Web Application Development with AngularJS 读书笔记-前记
学习AngularJS的笔记,这个是英文版的,有些地方翻译的很随意,做的笔记不是很详细,用来自勉.觉得写下来要比看能理解的更深入点.有理解不对的地方还请前辈们纠正! 一.关于<Mastering ...
- Mastering Web Application Development with AngularJS 读书笔记(二)
第一章笔记 (二) 一.scopes的层级和事件系统(the eventing system) 在层级中管理的scopes可以被用做事件总线.AngularJS 允许我们去传播已经命名的事件用一种有效 ...
- Mastering Web Application Development with AngularJS 读书笔记(一)
第一章笔记 (一) 一.PS:运行时配置IIS <html> <head> <script src="angular.js"></scri ...
- WEB Application Development Integrator : 应用设置
1.1. 系统安装 应用 Oracle EBS WEB Application Development Integrator WEB ADI在Oracle EBS 11.5.10.* 版本 ...
- 【转载】MDX Step by Step 读书笔记(三) - Understanding Tuples (理解元组)
1. 在 Analysis Service 分析服务中,Cube (多维数据集) 是以一个多维数据空间来呈现的.在Cube 中,每一个纬度的属性层次结构都形成了一个轴.沿着这个轴,在属性层次结构上的每 ...
- Spring揭秘 读书笔记 三 bean的scope与FactoryBean
本书可作为王富强所著<<Spring揭秘>>一书的读书笔记 第四章 BeanFactory的xml之旅 bean的scope scope有时被翻译为"作用域&quo ...
- Struts2技术内幕 读书笔记三 表示层的困惑
表示层能有什么疑惑?很简单,我们暂时忘记所有的框架,就写一个注册的servlet来看看. index.jsp <form id="form1" name="form ...
- ES6读书笔记(三)
前言 前段时间整理了ES6的读书笔记:<ES6读书笔记(一)>,<ES6读书笔记(二)>,现在为第三篇,本篇内容包括: 一.Promise 二.Iterator和for of循 ...
- 《你必须知道的.NET》读书笔记三:体验OO之美
此篇已收录至<你必须知道的.Net>读书笔记目录贴,点击访问该目录可以获取更多内容. 一.依赖也是哲学 (1)本质诠释:“不要调用我们,我们会调用你” (2)依赖和耦合: ①无依赖,无耦合 ...
随机推荐
- 在VS里配置及查看IL
在VS里配置及查看IL 来源:网络 编辑:admin 在之前的版本VS2010中,在Tools下有IL Disassembler(IL中间语言查看器),但是我想直接集成在VS2012里使用,方法如下: ...
- PHP serialize && unserialize Security Risk Research
目录 . 序列化的定义 . serialize:序列化 . unserialize:反序列化 . 序列化.反序列化存在的安全风险 . Use After Free Vulnerability -] . ...
- Windows装机必备软件列表
经常装系统,列个List,以后装完之后安装软件直接参照使用!windows版: 输入法: 搜狗输入法(由于长期使用导致此输入法十分熟悉我的输入习惯,以无法自拔).支持Linux.Windows(太穷还 ...
- JSONArray的使用
用的是fastjson.jar包 1. jsonarray,jsonobject 使用正确代码如下:(这种getJSONObject 函数形成jsonobj 的方式非常好,可以避免循环引用或jsono ...
- python函数(五)
函数 1.函数基本语法及特性 背景提要 现在老板让你写一个监控程序,监控服务器的系统状况,当cpu\memory\disk等指标的使用量超过阀值时即发邮件报警, 你掏空了所有的知识量,写出了以下代码 ...
- javascript之查找数组中最小/最大的数
实现原理:和数组的顺序查找很类似,都是逐个数据的比对. 废话不多说~ 代码如下: /* * 参数说明: * array:传入数组 ,例如:var arr = [5,7,66,78,99,103,126 ...
- JQuery------Select标签的各种使用方法
optioin属性(value) <option value='>Hello</option> option的点击事件 <select class="s-one ...
- 词性标注 parts of speech tagging
In corpus linguistics, part-of-speech tagging (POS tagging or POST), also called grammatical tagging ...
- Linux下的网络环境配置
- JavaScript学习笔记——DOM_对document对象的内容、属性、样式的操作
javascript-对文档对象的内容.属性.样式的操作 一.操作内容 1. innerHTML 用来设置或获取对象起始和结束标签内的内容(识别html标签) 2. innerText 用来设置或获取 ...