首页 > Web开发 > 详细

如何使用angularjs操作cookie

时间:2016-01-31 13:29:13      阅读:390      评论:0      收藏:0      [点我收藏+]
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html ng-app="myApp">
<head>
<title>angularjs-cookie</title>
<script type="text/javascript" src="js/angular/angular.min.js"></script>
<script type="text/javascript" src="js/angular/angular-cookies.min.js"></script>
</head>
<body>
<form name="form1" ng-controller="form1">
    <input type="text" name="input1" value="" ng-model="input1" />
    <input type="button" value="保存cookie" ng-click="saveCookie()" />
    <input type="button" value="删除cookie" ng-click="removeCookie()" />
<script>
    var app = angular.module(myApp,[ngCookies]);
    app.controller("form1",function($cookieStore,$scope){
        if($cookieStore.get("a1")) {
            $scope.input1 = $cookieStore.get("a1");
            alert("加载cookie成功!");
        }
        $scope.saveCookie = function() {
            $cookieStore.put("a1",$scope.input1);
            alert("保存cookie成功!");
        };
        $scope.removeCookie = function() {
            $cookieStore.remove("a1");
            alert("删除cookie成功!");
        };
    });
    </script>
    </form>
</body>
</html>

 

如何使用angularjs操作cookie

原文:http://www.cnblogs.com/modou/p/5173121.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!