The ngCookies module provides a convenient wrapper for reading and writing browser cookies. By using cookieStore and cookie, we can read and write cookies. Add angular and angular-cookie script to your page.
<script src="http://code.angularjs.org/1.0.0rc10/angular-1.0.0rc10.js"></script>
<script src="http://code.angularjs.org/1.0.0rc10/angular-cookies-1.0.0rc10.js"></script>

Using $cookieStore

    angular.module('myApp', ['ngCookies']);
    function CookieCtrl($scope, $cookieStore) {
      
      $scope.setCookie = function(){
          $cookieStore.put('name', 'srinivas');
          alert('cookie was set');
      };

      $scope.readCookie = function(){
          alert($cookieStore.get('name'));
      };
      
      $scope.removeCookie = function(){
          $cookieStore.remove('name');
          alert('cookie was removed');
      }; 
    }

Using $cookies

angular.module('myApp', ['ngCookies']);
    function CookieCtrl($scope, $cookies) {
      
      $scope.setCookie = function(){
          $cookies.name = 'srinivas';
          alert('cookie was set');
      };

      $scope.readCookie = function(){
          alert($cookies.name);
      };
      
      $scope.removeCookie = function(){
          $cookies.name = null;
          alert('cookie was removed');
      };    
    }

2 comments:

  1. Good blog. Keep sharing. I love them Are you also searching for Cheap assignment help? we are the best solution for you. We are best known for delivering cheap assignments to students without having to break the bank

    ReplyDelete

Blogroll

Popular Posts