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)依赖和耦合: ①无依赖,无耦合 ...
随机推荐
- 【codevs1043】 方格取数
http://codevs.cn/problem/1043/ (题目链接) 题意 N*N的方格,每个格子中有一个数,寻找从(1,1)走到(N,N)的两条路径,使得取到的数的和最大. Solution ...
- 前端打包/自动化构建工具:fis3
据说这个可以进行打包,并且可以实现类似/script/test-adsf123.js或者/script/test.js?v=asdf123 先做个记号 参考:http://fis.baidu.com/
- asp.net MVC中获取当前URL/Controller/Action
一.获取URL(ASP.NET通用): [1]获取完整url(协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取虚拟目录名+页面 ...
- xml解析模块
XML XML是可扩展标记语言的缩写,是实现不同语言或程序之间进行数据交换的协议,主要可以对key添加属性. 页面做展示(字符类型的一个xml格式数据)\做配置文件(内部xml格式的数据).,每一个节 ...
- CentOS禁用触摸板
安装xorg-x11-apps包 yum install xorg-x11-apps 查看设备信息 cd /dev/input/ ls //找到触摸板信息 xinput list //找到触摸板的id ...
- primefaces p:tableData 显示 List<List>
@javax.faces.bean.ViewScoped public class Controlador { private List<List> estadistico; @PostC ...
- DIY(码表)制作实验
代码: #include<reg52.h>typedef unsigned char u8;typedef unsigned int u16;/********端口定义********* ...
- Lambda表达式 和 Expression<T>
经常用的Lambda表达式 返回的是 Expression<T> 格式 public class ActivityService { private readonly List<A ...
- JQuery------如何判断当前点击的是否是哪个类
$(document).ready(function () { $("html").click(function (e) { if (e.target == $(".ad ...
- WinForm------TreeList属性介绍
转载: http://blog.csdn.net/fwj380891124/article/details/6888077 treeList1.LookAndFeel.UseWindowsXPThem ...