<!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. linux内核(四)内存管理单元MMU

    1,基本概念 一个程序运行时没必要全部都同时装入内存,只需要把当前需要运行的部分装入内存即可,这样就使得一个大程序可以在较小的内存中运行,也使得内存中可以同时装入更多的程序并发执行,从用户角度看,该系 ...

  2. 改动购物项图书数量的Ajax处理

    一.cart.jsp页面 <%@ page language="java" contentType="text/html; charset=utf-8" ...

  3. uva725_一道水题(优化到了29ms)

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  4. hdoj 1013Digital Roots

     /*Digital Roots Problem Description The digital root of a positive integer is found by summing th ...

  5. C#各个版本中的新增特性详解【转】

    序言 自从2000年初期发布以来,c#编程语言不断的得到改进,使我们能够更加清晰的编写代码,也更加容易维护我们的代码,增强的功能已经从1.0搞到啦7.0甚至7.1,每一次改过都伴随着.NET Fram ...

  6. 用ksh运行一个helloworld

    本文目的在于记录和回顾.不建议当教程. Linux上没有ksh的话yum install ksh就可以了 直接上图 vim一个文件后缀名是ksh 内容是和shell差不多 然后赋予这个文件可执行权限 ...

  7. excel文件使用html导出

    <table><tr><td>1</td></tr><tr><td>2</td></tr>& ...

  8. NPOI 给导出Excel添加简单样式

    需求分析:如下图为我之前导出的Excel数据,没有一点样式,标题行不明显,各个列的数据紧凑,查看数据时得手动拉宽每列,故这次要针对以上问题对它进行优化 结果展示: 代码: /// <summar ...

  9. Pyinstaller 1 使用PyInstaller

    使用PyInstaller pyinstaller命令的语法是: pyinstaller[ options ] script [ script ...] | spec文件 在最简单的情况下,将当前目录 ...

  10. C#生成高清缩略图 (装在自OPEN经验库)

    来源 http://www.open-open.com/lib/view/open1389943861320.html 代码如下实现图片的高清缩略图 /// <summary> /// 为 ...