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>
angularjs1-8,cacheFactory,sce的更多相关文章
- ngSanitize和$sce
(angular-ngSanitize模块-$sanitize服务详解) 本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一 ...
- Angularjs1培训
Angularjs1培训: angularjs解决什么问题? 从无穷无尽的DOM操作中解放出来,专注于业务逻辑,DOM操作不叫业务逻辑,那是试图呈现. 组件化,模块化为构建大型项目铺平道路,模块发开发 ...
- angular源码分析:angular中入境检察官$sce
一.ng-bing-html指令问题 需求:我需要将一个变量$scope.x = '<a href="http://www.cnblogs.com/web2-developer/&qu ...
- AngularJS1.3一些技巧
前言 框架选择.在上一篇文章评论中,有人说angular1.3是个过时的东西,建议使用angular2.其实这种说法很像拿jQuery1.x和jQuery2.x做比较,新的版本当然会有优化优势的地方, ...
- AngularJs $sce 和 $sceDelegate 上下文转义
$sce $sce 服务是AngularJs提供的一种严格上下文转义服务. 严格的上下文转义服务 严格的上下文转义(SCE)是一种需要在一定的语境中导致AngularJS绑定值被标记为安全使用语境的模 ...
- AngularJs $cacheFactory 缓存服务
可能之前的api写的有些枯燥吧,因为不烧脑,不需要很多逻辑思维来做处理,那么之后的文章会有趣很多,慢慢的开始烧脑了,准备好大量脑细胞的死亡吧~ 先来篇简单的缓存服务. 本文将api文档里的$cac ...
- AngularJS 使用$sce控制代码安全检查
由于浏览器都有同源加载策略,不能加载不同域下的文件.也不能使用不合要求的协议比如file进行访问. 在angularJs中为了避免安全漏洞,一些ng-src或者ng-include都会进行安全校验,因 ...
- angular中$cacheFactory缓存的使用
最近在学习使用angular,慢慢从jquery ui转型到用ng开发,发现了很多不同点,继续学习吧: 首先创建一个服务,以便在项目中的controller中引用,服务有几种存在形式,factory( ...
- [AngularJS] Html ngSanitize, $sce
Safely render arbitrary HTML snippets by using ngSanitize and $sce. By default angularJS consider us ...
随机推荐
- Excel 查找某列中的数据在另一列是否存在并输出其他列的数据
最近在操作Excel文件数据导入数据库时,经常需要检查Excel中哪些数据数据库中已经存在,哪些不存在,然后再将不存在数据库中的Excel数据导入:在此过程中,经常需要操作Excel中的数据,所以.也 ...
- python之路——迭代器和生成器
阅读目录 楔子 python中的for循环 可迭代协议 迭代器协议 为什么要有for循环 初识生成器 生成器函数 列表推导式和生成器表达式 本章小结 生成器相关的面试题 返回顶部 楔子 假如我现在有一 ...
- 在Mac OSX上安装ffmpeg && ffmpeg命令行将h264封装为mp4
ffmpeg功能强大,可以通过命令行来对音视频进行处理.为了使用其功能,我在Mac上对其进行了安装. 我的Mac OS X 系统版本:OS X Yosemite, 10.10.14 关于ffmpeg在 ...
- DropDownListFor
- (转) 50个CSS技巧
这里我工作中收集了10个很不错的CSS技巧,你可以用在你的项目上.它可以帮你很好地整理你的元素并让他们看起来蛮酷的.下面开始我们的内容,希望你会喜欢它.下面是我收集的CSS技巧,希望能帮助到你,感觉收 ...
- hdu3861 The King’s Problem 强连通缩点+DAG最小路径覆盖
对多校赛的题目,我深感无力.题目看不懂,英语是能懂的,题目具体的要求以及需要怎么做没有头绪.样例怎么来的都不明白.好吧,看题解吧. http://www.cnblogs.com/kane0526/ar ...
- spring boot (一)
spring boot 启动注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIM ...
- JA document的练习
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- windows mongodb启动
D:\MongoDB\bin\mongod.exe --service --dbpath D:\MongoDB\data --logpath=D:\MongoDB\logs\mongodb.log - ...
- tomcat-manager 设置
tomcat默认是没有用户登录控制的,需要登录manager,则需要配置角色与用户 1. 在conf/tomcat-users.xml中添加 <role rolename="manag ...