angularjs1-8,cacheFactory,sce

<!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 #000 solid; margin:20px;}
#parent ul{ width:200px; position:fixed; top:0; right:0;}
</style>
<script src="angular.min.js"></script>
<script> var m1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope','$cacheFactory',function($scope,$cacheFactory){
//localstorage写入永久缓存,sessionstorage浏览器不关闭就有,cacheFactory只要put不写就get不到了,cacheFactory只是用于多个controller临时数据共享,没有写入storage。多个controller临时数据共享也可以通过自定义服务来实现。
var cache=$cacheFactory('cacheId');
cache.put('name','张三');
cache.put('age','20');
var name=cache.get('name');
console.log(name);
}]);
m1.controller('Bbb',['$scope','$cacheFactory',function($scope,$cacheFactory){
var cache=$cacheFactory.get('cacheId');
var name=cache.get('name');
var age=cache.get('age');
console.log(name);
console.log(age);
}]); </script>
</head>
<body>
<div ng-controller="Aaa">
</div>
<div ng-controller="Bbb">
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
{{name}}
<div ng-bind-html="text"></div>
<div ng-bind-html="detailContent()"></div>
1111111111
<div ng-bind-html="portalDetail"></div>
</div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller('firstController',function($scope,$timeout,$sce,$http){//依赖注入$sce
$scope.name = 'hello';
//sce服务用于解析html,
$scope.text = $sce.trustAsHtml('<h1>hello text</h1>');
var myUrl = "http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=338&callback=JSON_CALLBACK";
$http.jsonp(myUrl).success(
function(data){
$scope.portalDetail = $sce.trustAsHtml(data.result[0].content);
$scope.detailContent = function() {
return $sce.trustAsHtml(data.result[0].content);
};
}
).error(function(){
alert('失败');
});
});
</script>
</body>
</html>
上一篇:Linux下mongodb环境经常挂掉解决方法脚本


下一篇:在Linux使用mingw32来编写win32程序