Want to access cookies in AngularJS? You need to use $cookieStore
instead of $cookies
to access cookies using AngularJS.
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!DOCTYPE html> <html ng-app="myApp"> <head> <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> <script> angular.module('myApp', ['ngCookies']); function CookieCtrl($scope, $cookieStore) { $scope.lastVal = $cookieStore.get('tab'); $scope.changeTab = function(tabName){ $scope.lastVal = tabName; $cookieStore.put('tab', tabName); }; } </script> </head> <body ng-controller="CookieCtrl"> <!-- ... --> </body> </html> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.