angularjs - Angular 1.4.1 $cookies ending up as session cookies -
i having problem setting persistent cookies under angular 1.4.1 cookies end (according chrome's resource inspection, , more obvious effect of closing browser , reopening page) session cookies.
$scope.hidesystemnotice = function() { // set expiry 1 yr in future - after system notice expires var = new date(), exp = new date(now.getfullyear()+1, now.getmonth(), now.getdate()) $cookies.put( 'snotice'+$scope.systemnoticeinfo[0].snid, // cookiename 'dismissed', // value { 'expires': exp } // expiry ); $scope.nextsystemnotice(); }; this same examples provided elsewhere on stackoverflow (but lack rep add convos :( separate question)
the cookies being set - can see them show in chrome's resource view. however, have no expiry date (chrome shows them "session").
what obvious tidbit have missed in setting date? thanks.
edit....
i'm still having problems setting expiry date. i've upgraded angular 1.4.7 now, , have tried using $cookiesprovider defaults in .config no benefit
app.config(function($cookiesprovider) { var n = new date(); $cookiesprovider.defaults = { path: '/', domain: location.hostname, secure: true, expires: new date(n.getfullyear()+1, n.getmonth(), n.getdate()) }; }); then further down in code:
$scope.hidesystemnotice = function() { $cookies.put('snotice'+$scope.systemnoticeinfo[0].snid, 'dismissed'); $scope.nextsystemnotice(); }; and i'm still seeing session cookies being created.
the path , domain correct, cookie not being tagged secure, options (or in latest incarnation, defaults) not being applied (i dont seem need set path or domain, set regardless).
can point out incorrect in either piece of code?
had same problem , found solution here. thing is, shouldn't create new object (assigning {...} defaults), edit properties of defaults object this:
app.config(function($cookiesprovider) { var n = new date(); $cookiesprovider.defaults.path = '/'; $cookiesprovider.defaults.domain = location.hostname; $cookiesprovider.defaults.secure = true; $cookiesprovider.defaults.expires = new date(n.getfullyear()+1, n.getmonth(), n.getdate()); });
Comments
Post a Comment