Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (47.6k points)

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?

1 Answer

0 votes
by (106k points)
edited by

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:

Note you should use $cookieStore instead of $cookies.

<!DOCTYPE html> 

<html ng-app="myApp"> 


<script src="">


<script src=""></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); 




<body ng-controller="CookieCtrl"> </body> 


Related questions

Browse Categories