2015-06-10 22 views
7

tôi thiết lập ngày hết hạn của cookie theo cách sau đây:

var dt = new Date(); 
dt.setMinutes(dt.getMinutes() + 30);       

$cookieStore.put("loggedin", true, { expires: dt }) 

Các cookie được tạo ra nhưng hết nó cho thấy là "Khi phiên duyệt kết thúc". Wth?

+0

Theo tôi biết $ cookieStore không có tùy chọn đặt hết hạn. Nó chỉ chấp nhận 2 tham số. https://code.angularjs.org/1.3.16/docs/api/ngCookies/service/$cookieStore để biết thêm chi tiết. –

+0

Bạn nói đúng. Google đã đưa tôi đến đây https://code.angularjs.org/1.4.0/docs/api/ngCookies/service/$cookies và tôi nhận được tất cả các phiên bản với các phiên bản góc và $ cookie vs $ cookieStore – americanslon

+0

Ahh ok ... Sai lầm trung thực !! :-) –

Trả lời

0

Đặt thuộc tính cookie ở cấp cấu hình cho tất cả cookie (sử dụng moment.js để đặt ngày hết hạn).

angular.module('myApp').config(cookies); 

function cookies($cookiesProvider, moment) { 
    // site domain like: domine.com 
    $cookiesProvider.defaults.domain = 'yourdomine.com'; 
    // set expiration to next week (+ 1 week) 
    $cookiesProvider.defaults.expires = moment().add(1, 'week').calendar(); 
    // see HTTP cookies to view attributes 
}