angularjs - Cookie is still present after expiration date -
so i'm trying use ngcookie ($cookies) set boolean in angularjs. can see in example below, "someflag" should true, if cookie still present. cookie expiration set 30 seconds, after 30 seconds, "someflag" still true.
so how manage find out wether cookie expired or not?
var peekerhidecookie = $cookies.get('peekerhidecookie'); console.log(peekerhidecookie); if (peekerhidecookie == 'true'){ $scope.someflag = true; } $scope.test = function () { var d = new date(); d.setdate(d.getseconds() + 30); $cookies.put('peekerhidecookie', 'true', {expires: d}); $scope.someflag = true; }
use d.setseconds(d.getseconds() + 30)
insetead of d.setdate()
$scope.test = function () { var d = new date(); d.setseconds(d.getseconds() + 30); $cookies.put('peekerhidecookie', 'true', {expires: d}); $scope.someflag = true; }
var d = new date(); console.log(d); d.setseconds(d.getseconds() + 30); console.log(d);
Comments
Post a Comment