<!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", function ($scope, $cacheFactory) {
var table = $cacheFactory.get('kwc');
console.log(table.get("hero").name);
});
</script>
</html>
angular缓存及多个controller间的共享
最新推荐文章于 2021-06-18 16:47:00 发布