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 ...
随机推荐
- oracle scott趣事
Oracle里面是scott是个什么用户呢? 这个就要追朔到Oracle的创业阶段了, 1977年6月,埃里森,Bob Miner和Ed Oates在硅谷共同创办了一家名为软件开发实验室(Softwa ...
- url 域名 主机名
1. url = 协议//主机名(包括服务器的计算机名+域名)/路径 https:// i. cnblogs.com /index.html .com是顶级域名,从右向左,每碰到一个".&q ...
- MySQL 5.6 Reference Manual-14.5 InnoDB Tablespace Management
14.5 InnoDB Tablespace Management 14.5.1 Resizing the InnoDB System Tablespace 14.5.2 Changing the ...
- Python操作Oracle
[root@oracle02 pythonsoftware]# rpm -ivh oracle-instantclient-basic-11.1.0.1-1.x86_64.rpm Preparing. ...
- 【Vue+Node】解决axois请求数据跨域问题
项目基于Vue前端+Node后台,启动两个服务,请求数据时,端口不一致造成跨域报错: (No 'Access-Control-Allow-Origin' header is present on th ...
- Robot Framework(四)创建测试套件
2.3.1测试用例文件 Robot Framework测试用例是使用测试用例文件中的测试用例表创建的.这样的文件会自动从它包含的所有测试用例中创建一个测试套件.可以有多少测试用例没有上限,但建议少于1 ...
- javaee 文件的读取
package Shurushucu; import java.io.FileNotFoundException; import java.io.FileOutputStream; import ja ...
- linux系统时间与网络时间不同步
在解决问题之前,我们首先来了解下面几个知识点: 1. date命令: #date 显示系统时间 2.hwclock命令 (即hardwareclock系统硬件时间) #hwclock 显示硬件时间 ...
- Ubuntu Server 与 Ubuntu Desktop区别
今天有位朋友问我,Ubuntu Server 与 Ubuntu Desktop的区别在哪里!区别如下: SERVER没有GUI SERVER没有一堆的桌面软件 SERVER在编译时使用的参数不一样,会 ...
- 了解http协议
http:超文本传输协议 https:安全超文本传输协议 FTP:文件传输协议 TCP:网络控制协议 IP:互联网协议 UDP:用户数据协议 https协议特点-------------------- ...