<!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的更多相关文章

  1. ngSanitize和$sce

    (angular-ngSanitize模块-$sanitize服务详解) 本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一 ...

  2. Angularjs1培训

    Angularjs1培训: angularjs解决什么问题? 从无穷无尽的DOM操作中解放出来,专注于业务逻辑,DOM操作不叫业务逻辑,那是试图呈现. 组件化,模块化为构建大型项目铺平道路,模块发开发 ...

  3. angular源码分析:angular中入境检察官$sce

    一.ng-bing-html指令问题 需求:我需要将一个变量$scope.x = '<a href="http://www.cnblogs.com/web2-developer/&qu ...

  4. AngularJS1.3一些技巧

    前言 框架选择.在上一篇文章评论中,有人说angular1.3是个过时的东西,建议使用angular2.其实这种说法很像拿jQuery1.x和jQuery2.x做比较,新的版本当然会有优化优势的地方, ...

  5. AngularJs $sce 和 $sceDelegate 上下文转义

    $sce $sce 服务是AngularJs提供的一种严格上下文转义服务. 严格的上下文转义服务 严格的上下文转义(SCE)是一种需要在一定的语境中导致AngularJS绑定值被标记为安全使用语境的模 ...

  6. AngularJs $cacheFactory 缓存服务

    可能之前的api写的有些枯燥吧,因为不烧脑,不需要很多逻辑思维来做处理,那么之后的文章会有趣很多,慢慢的开始烧脑了,准备好大量脑细胞的死亡吧~   先来篇简单的缓存服务. 本文将api文档里的$cac ...

  7. AngularJS 使用$sce控制代码安全检查

    由于浏览器都有同源加载策略,不能加载不同域下的文件.也不能使用不合要求的协议比如file进行访问. 在angularJs中为了避免安全漏洞,一些ng-src或者ng-include都会进行安全校验,因 ...

  8. angular中$cacheFactory缓存的使用

    最近在学习使用angular,慢慢从jquery ui转型到用ng开发,发现了很多不同点,继续学习吧: 首先创建一个服务,以便在项目中的controller中引用,服务有几种存在形式,factory( ...

  9. [AngularJS] Html ngSanitize, $sce

    Safely render arbitrary HTML snippets by using ngSanitize and $sce. By default angularJS consider us ...

随机推荐

  1. JWT和Spring Security集成

    通常情况下,把API直接暴露出去是风险很大的, 我们一般需要对API划分出一定的权限级别,然后做一个用户的鉴权,依据鉴权结果给予用户对应的API (一)JWT是什么,为什么要使用它? 互联网服务离不开 ...

  2. 关于一些UI的插件(杂)

    1.时间插件 //日期框 $('.date-picker').datepicker(); 2.checkbox 保存checkbox的值 // 组装选择的标签 var check = $(" ...

  3. [hihicoder][Offer收割]编程练习赛47

    删除树节点 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #inclu ...

  4. 动画库animate.css的用法

    简介 animate.css是一个来自国外的 CSS3 动画库,它预设了引起弹跳(bounce).摇摆(swing).颤抖(wobble).抖动(shake).闪烁(flash).翻转(flip).旋 ...

  5. c++ windows与linux通信中文乱码问题解决方法

    在linux中默认编码方式是UTF-8,在Windows下默认编码方式时GB2312.因此,在Windows和Linux进行通信的时候,如果没有进行转码则会出现乱码问题.因此,需要进行UTF-8和GB ...

  6. java加密解密算法位运算

    一.实例说明 本实例通过位运算的异或运算符 “ ^ ” 把字符串与一个指定的值进行异或运算,从而改变每个字符串中字符的值,这样就可以得到一个加密后的字符串.当把加密后的字符串作为程序输入内容,异或运算 ...

  7. 了解 object.defineProperty 的基本使用方法(数据双向绑定的底层原理)

    Object.defineProperty 给一个对象定义一个新的属性或者在修改一个对象现有的属性,并返回这个对象 语法: Object.defineProperty(参数1,参数2,参数3) 参数1 ...

  8. HDU1079-Calendar Game 简单思维博弈··

    题意:给你1990,1.1----2001.11.4范围内的某一天,格式year month day  两人轮流操作: 1. day+1; 2.month + 1: 谁先达到2001.11.4号,谁获 ...

  9. spring实现定时任务的两种方式之spring @scheduled注解方式

    1.使用spring的 scheduled使用注解的方式 这种方法的好处是:使用方便,配置少,提高开发效率: 缺点是:如果使用服务器集群部署方式的时候,其自身无法解决定时任务重复执行的问题. 2.首先 ...

  10. RobotFrameWork+APPIUM实现对安卓APK的自动化测试----第七篇【元素定位介绍】

    http://blog.csdn.net/deadgrape/article/details/50628113 我想大家在玩自动化的时候最关心的一定是如何定位元素,因为元素定位不到后面的什么方法都实现 ...