<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
#parent div{ width:300px; height:500px; border:1px # solid; margin:20px;}
#parent ul{ width:200px; position:fixed; top:; right:;}
</style>
<script src="angular.min.js"></script>
<script> var m1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope','$cacheFactory','$log',function($scope,$cacheFactory,$log){
$log.error('hello'); //调试
var cache = $cacheFactory('myCache',{capacity : });//myCache缓存的名字, cache.put('name','hello');
cache.put('age','');
cache.put('job','it'); console.log(cache.info());
console.log(cache.get('name'));
cache.remove('name');
console.log(cache.get('name'));
}]);
</script>
</head>
<body>
<div ng-controller="Aaa">
</div>
</body>
</html>
<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
#parent div{ width:300px; height:500px; border:1px # solid; margin:20px;}
#parent ul{ width:200px; position:fixed; top:; right:;}
</style>
<script src="angular.min.js"></script>
<script>
$q对异步操作进行功能扩展。 var m1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope','$q',function($scope,$q){ var dfd = $q.defer();//创建延迟对象
function show(){
setTimeout(function(){
dfd.reject();//失败时候触发
},);
return dfd.promise;
}
show().then(function(){
alert('成功');
},function(){
alert('失败');
});
}]);
</script>
</head> <body>
<div ng-controller="Aaa">
</div>
</body>
</html>

angularjs 缓存 $q的更多相关文章

  1. angularJS promise $q

    Promise 一 介绍 1.什么是promise 我们知道JavaScript语言的执行环境是“单线程”,所谓单线程,就是一次只能够执行一个任务,如果有多个任务的话就要排队,前面一个任务完成后才可以 ...

  2. angularJS $http $q $promise

    一天早晨,爹对儿子说:“宝儿,出去看看天气如何!” 每个星期天的早晨,爹都叫小宝拿着超级望远镜去家附近最高的山头上看看天气走势如何,小宝说没问题,我们可以认为小宝在离开家的时候给了他爹一个promis ...

  3. angularjs 缓存

    设置缓存请求的数据:只有请求URL不变,就不会重新发请求 设置带定时时间的缓存: .factory('cacheInterceptor', ['$cacheFactory', '$timeout', ...

  4. angularJS中的Promise对象($q)的深入理解

    原文链接:a better way to learn AngularJS - promises AngularJS通过内置的$q服务提供Promise编程模式.通过将异步函数注册到promise对象, ...

  5. AngularJS 承诺 Promise

    一.概念解释 全称是未来与承诺,Futures and promises,是一种编程模式,不是AngularJS首创.javascript里有个流行库Q,而AngularJS是$q,其就是从Q引入的: ...

  6. promise理解

    每个操作都返回一样的promise对象,保证链式操作 每个链式都通过then方法 每个操作内部允许犯错,出了错误,统一由catch error处理 操作内部,也可以是一个操作链,通过reject或re ...

  7. Node.js最新技术栈之Promise篇

    前言 大家好,我是桑世龙,github和cnodejs上的i5ting,目前在天津创业,公司目前使用技术主要是nodejs,算所谓的MEAN(mongodb + express + angular + ...

  8. promise、resolve、reject、拦截响应

    Promise是一个接口,它用来处理的对象具有这样的特点:在未来某一时刻(主要是异步调用)会从服务端返回或者被填充属性.其核心是,promise是一个带有then()函数的对象. 使用promise机 ...

  9. IGS_学习笔记03_Integrated SOA Gateway设定配置(案例)

    20150506 Created By BaoXinjian

随机推荐

  1. 监控myserver计数器

  2. Eureka Server的REST端点

    Eureka Server的REST端点 Windows下面可以安装Curl: 使用more命令可以显示xml内容: D:\Java\IdeaProjects>more rest-api-tes ...

  3. PyQt: LineEdit的智能输入提示

    使用的的类是QtGui.QCompleter from PyQt4 import QtGui,QtCore str = QtCore.QStringList(['a','air','airbus']) ...

  4. start_kernel——boot_cpu_init及PER_CPU

    init/main.c /* * Activate the first processor. */ static void __init boot_cpu_init(void) { int cpu = ...

  5. Javaee 应用分层架构

    应用分层的优点:修改方便,仅修改有问题的那层以及其相邻几层即可,层数越多,其相应的资源分配也会更加平均 缺点:耗费时间,速度慢,调用占用大量堆栈. JAVAEE的分层: 4层分法:1.客户层:运行在客 ...

  6. bzoj5105: [CodePlus2017]晨跑(LCM)

    5105: [CodePlus2017]晨跑 题目:传送门 题解: 没有很懂Code Puls 的操作...一道签到的三个数的LCM??? 代码: #include<cstdio> #in ...

  7. bzoj2229: [Zjoi2011]最小割(分治最小割+最小割树思想)

    2229: [Zjoi2011]最小割 题目:传送门 题解: 一道非常好的题目啊!!! 蒟蒻的想法:暴力枚举点对跑最小割记录...绝对爆炸啊.... 开始怀疑是不是题目骗人...难道根本不用网络流?? ...

  8. Forms authentication timeout vs sessionState timeout

    https://stackoverflow.com/questions/17812994/forms-authentication-timeout-vs-sessionstate-timeout Th ...

  9. java布局管理

    FlowLayout :组件在一行中按加入的先后顺序从左至右水平排列,排满后折行,每行中的组件都居中排列.BorderLayout:把容器空间划分为北.南.西.东.中五个区,每加入一个组件都应说明把这 ...

  10. NOIP 2012 T2 国王游戏 (贪心+高精)

    思路: 呃呃网上那么多题解写得都不错-.. 就是高精 巨坑... 这里展出的是任氏高精(纯自己yy滴) //By SiriusRen #include <cstdio> #include ...