[英]How to store the cookies from one session and restore the same cookies by refreshing the page in AngularJS?
我為選項選擇和單選按鈕有兩個輸入項。 一旦用戶選擇了“選項選擇”(例如,值為ABCD)和“單選”按鈕(例如,值為R)。
現在,用戶刷新頁面,並希望使用選項選擇(ABCD)和單選按鈕(R)的默認值預填充頁面。
我一直在嘗試使用ngCookies。 我可以在同一會話中設置並獲取Cookie。 刷新頁面后,這些值將變為null。 例如$ cookies.put('selectOption',$ scope.selectValue)$ cookies('radioSelection',$ scope.radioValue)
要獲取值,$ cookie.get('selectOption')和$ cookie.get('radioSelection');
基本上,使用一些默認值重新創建頁面。
請幫助我實現這一目標。
我想您每次刷新時都會重置選擇框值,因此添加一個if語句,例如
if (!$cookie.get('selectOption') ) {
$cookies.put('selectOption', $scope.selectValue)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.