Back
What's the AngularJS way to access cookies? I've seen references to both a service and a module for cookies, but no examples.
Is there, or is there not an AngularJS canonical approach?
If you want to access cookies in AngularJS then you can set and get cookie values.
Are you interested in learning Angularjs from the basics! Here's the right video for you on Angularjs provided by Intellipaat:
<!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>
<!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);
};
}
</head>
<body ng-controller="CookieCtrl"> </body>
</html>
31k questions
32.8k answers
501 comments
693 users