AngularJS Factory Service Provider
先看看http://www.cnblogs.com/mbydzyr/p/3460501.html
http://www.oschina.net/translate/angularjs-factory-vs-service-vs-provider
使用factory创建服务
<!doctype html>
<html ng-app='ShoppingModule'> <head>
<meta charset="UTF-8">
<script src="angular.js"></script>
<script src="controller2.js"></script>
</head> <body ng-controller="ShoppingController">
<h1>Shop!</h1>
<table>
<tr ng-repeat='item in items'>
<td>{{item.title}}</td>
<td>{{item.description}}</td>
<td>{{item.price | currency}}</td>
</tr>
</table>
</div> </html>
JS
var shoppingModule = angular.module('ShoppingModule', []);
shoppingModule.factory('Items', function() {
var items = {};
items.query = function() {
// 在真实的应用中,我们会从服务端拉取这块数据 ...
console.log('service');
return [
{
title: 'Paint pots',
description: 'Pots full of paint',
price: 3.95
}, {
title: 'Polka dots',
description: 'Dots with polka',
price: 2.95
}, {
title: 'Pebbles',
description: 'Just little rocks',
price: 6.95
}
];
};
return items;
});
function ShoppingController($scope, Items) {
//console.log(Items.query());
$scope.items = Items.query();
}
AngularJS Factory Service Provider的更多相关文章
- angularjs factory,service,provider 自定义服务的不同
angularjs框架学了有一段时间了,感觉很好用.可以把angularjs的app理解成php的class,controller是控制器,而内置服务和自定义服务就可以理解成models了.angul ...
- AngularJS 讲解五, Factory ,Service , Provider
一. 首先说一下,为什么要引入Factory,Service和Provider这三个Service层. 1.因为我们不应该在controller层写入大量的业务逻辑和持久化数据,controller层 ...
- angularjs 中 Factory,Service,Provider 之间的区别
本片文章是使用了 angularjs 中使用 service 在controller 之间 share 对象和数据 的code(http://jsfiddle.net/kn46u0uj/1/) 来进行 ...
- [译]AngularJS中几种Providers(Factory, Service, Provider)的区别
原文: http://blog.xebia.com/2013/09/01/differences-between-providers-in-angularjs/ 什么是Provider? Angula ...
- angula的factory service provider
本人学了一段时间的angular的服务(factory.service.provider),有了自己的一些对于他们的见解,如果说的对,敬请赐教!!! 以后更新
- AngularJS中的Provider们:Service和Factory等的区别
引言 看了很多文章可能还是不太说得出AngularJS中的几个创建供应商(provider)的方法(factory(),service(),provider())到底有啥区别,啥时候该用啥,之前一直傻 ...
- Angular之Providers (Value, Factory, Service and Constant )
官方文档Providers Each web application you build is composed of objects that collaborate to get stuff do ...
- Angular1.x 之Providers (Value, Factory, Service and Constant )
官方文档Providers Each web application you build is composed of objects that collaborate to get stuff do ...
- AngularJs:Service、Factory、Provider依赖注入使用与区别
本教程使用AngularJS版本:1.5.3 AngularJs GitHub: https://github.com/angular/angular.js/ ...
随机推荐
- win8.1 安装webaccess遇到的写访问权限错误
大学的时候闲暇时间都用来玩游戏了,现在工作了,就把工作中遇到的问题和学习心得跟大家共享下,若有不对的地方欢迎指出,谢谢! 前几天突然想换用vs2013开发,就重装了win8.1系统,在新系统上安装we ...
- android上传位置信息导致的流量大爆炸问题调查
原由:项目中有人写了个位置上传的服务,其实一直没问题,后来不知道什么时候出现了很多抱怨,是开着app流量一下子跑掉了几个G,差点就要卖房子还移动话费了,很多同事哭笑不得的找上门来,后来PM解决了,我一 ...
- qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】
#include <QCoreApplication>#include <QDebug>#include <QTextStream>#include <QDi ...
- Struts学习之类型转换
* 从页面中获取对应的内容 * 在动作类action中,声明与页面中表单name属性的值同名的属性 * 提供get和set方法 * struts2框架就会通过 ...
- perl正则表达式第三周笔记
正则引擎的分类 正则引擎的分类 正则引擎的分类主要分两种: DFA:egrep.awk.lex.flex NFA:.NET.PHP.Perl.Ruby.Python.GNU Emacs.ed.sec. ...
- js写的简单轮播图
这个轮播图代码是从网上找来的,专门找了个写法简单的,只是作为一个小练习,大概原理如下: 1.首先是图片切换2.自动播放3.调用自动播放4.移动到容器上边停止播放,离开自动播放5.移动到导航上停止播放, ...
- WebWorker SharedWorker ServiceWorker
WebWorker 是什么? 为 JavaScript 引入线程技术 不必再用 setTimeout().setInterval().XMLHttpRequest 来模拟并行 Worker 利用类似线 ...
- Visual Studio 中用管理员权限运行、调试程序
原文:Visual Studio 中用管理员权限运行.调试程序 一个Sample小程序,用于验证WoW64的Windows Registry的读写访问.在Visual Studio 2010中调试运行 ...
- 清理8组nodes中表的历史数据,平均每个node中的表有1.5亿条记录,需要根据date_created字段清理8000W数据记录,这个字段没有索引。
清理8组nodes中表的历史数据,平均每个node中的表有1.5亿条记录,需要根据date_created字段清理8000W数据记录,这个字段没有索引. 环境介绍 线上磁盘空间不足,truncate ...
- mysql null值问题
mysql> create table test( sn int, -> `createdTime` datetime NOT NULL COMMENT '创建时间', -> `up ...