AngularJs的cookies例子

sk  10月前
0

直接放代码:

<head>

<!--引入angular和angular-cookies的模块-->

<script type="text/javascript" src="angular.js"></script>

<script type="text/javascript" src="angular-cookies.js"></script>

</head>

<div ng-app="cookiesMod" ng-controller="CookiesController" ng-init="init()">

<button ng-click="getInfo()">获取Cookies信息</button>

</div>

<script>

var cookiesMod = angular.module("cookiesMod",['ngCookies']);

        cookiesMod.controller("CookiesController",function($scope,$log,$cookieStore){

        $scope.init = function()

        {

            $log.info("init functionn");

            $cookieStore.put("person",{name:"SK",sex:"MAN"});

        }


        $scope.getInfo = function()

        {

            var person = $cookieStore.get("person");

            alert("name : " + person.name +" , "+ "sex : " + person.sex);

        }


    });

</script>

回复 2  
sk   10月前
1


angular.js  

sk   10月前
2


angular-cookies.js  

游客  现在


二维码