Getting a cookie in AngularJS can be done in a more standardized way. Instead of the traditional JavaScript approach, you can implement it using AngularJS code as shown below:
angular.module('myApp', [])
.factory('CookieService', function() {
return {
getCookie: function(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}
};
})
.controller('ModuleCtrl', ['$http', 'CookieService', function($http, CookieService) {
var self = this;
self.$http = $http;
self.CookieID = CookieService.getCookie('Id');
self.test = function() {
var params = {
testId: self.CookieID
}
}
}]);