zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    前端资源分享
    Java的wait(), notify()和notifyAll()使用心得(转)
    Java 理论与实践: 处理 InterruptedException(转)
    关于线程中断的总结
    Python入门(good)
    看着自己有什么样的资源,利用好这些资源就好了。不要看着别人的资源流口水(转)
    android手机SD卡中的android_secure目录
    Android中ExpandableListView控件基本使用
    华为的面试经历
    Flex强制类型转换错误
  • 原文地址:https://www.cnblogs.com/yaowen/p/7240962.html
Copyright © 2011-2022 走看看