前端之家收集整理的这篇文章主要介绍了
angular缓存及多个controller间的共享,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<title>angularjs缓存</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script src="jquery-2.1.3.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="angular.min.js"></script>
</head>
<body ng-app="kongwc">
<div ng-controller="myCtrl1"></div>
<div ng-controller="myCtrl2"></div>
</body>
<script>
var app = angular.module("kongwc",[]);
app.controller("myCtrl1",function ($scope,$cacheFactory) {
var table = $cacheFactory('kwc');
table.put('user',{id:1,name:'小白牛',phone : '13465352119'});
table.put('hero',{name: '裂魂人',skill : '暗影冲刺'});
//删除缓存
//删除某一个
//table.remove('user');
//全部删除
//table.removeAll();
//删除表
//table.destroy();
console.log(table.get("user"));
});
app.controller("myCtrl2",$cacheFactory) {
var table = $cacheFactory.get('kwc');
console.log(table.get("hero").name);
});
</script>
</html>
原文链接:https://www.f2er.com/angularjs/146968.html