How to change a cookie from javascript to angularjs -


i can cookie following. call cookie in module , pass parameter.

how change code cookie in standard angularjs code?

    $(document).ready(function() {          cookie();      });       function getcookie(cname) {          var name = cname + "=";          var ca = document.cookie.split(';');          (var = 0; < ca.length; i++) {              var c = ca[i].trim();              if (c.indexof(name) == 0) return c.substring(name.length, c.length);          }          return "";      }       function cookie() {          var cookie = getcookie('id');       }       function module($http) {          var self = this;          self.$http = $http;          self.cookieid = getcookie('id');           self.test = function() {              var params = {                  testid: self.cookieid              }          }      } 

angular ngcookies

first include angular-cookies.js in html:

<script src="angular.js"> <script src="angular-cookies.js"> 

then load module in application adding dependent module:

angular.module('app', ['ngcookies']); 

usage example

angular.module('cookiesexample', ['ngcookies']) .controller('examplecontroller', ['$cookies', function($cookies) {   // retrieving cookie   var favoritecookie = $cookies.get('myfavorite');   // setting cookie   $cookies.put('myfavorite', 'oatmeal'); }]); 

jquery

set cookie

$.cookie("my_cookie", value); 

set cookie expiration (in days) , path

$.cookie("my_cookie", value, { expires: 1, path: '/' }); 

remove cookie

$.removecookie("my_cookie"); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -