Priyanka Lopes Priyanka Lopes - 1 year ago 97
HTML Question

saving dropdown selection in cookie

I am totally new to Bootstrap and angularjs world and I am stuck at this.
I have a simple select like this below

<div class="pull-left margin-left-20">
<select id="ddlPageSize" class="form-control form-ddl-adj"
ng-options="item.value as item.text for item in params.settings().countOptions"

In the controller, I have select values like this

var pageSizeList = [
{ value: 5, text: "5" },
{ value: 10, text: "10" },
{ value: 25, text: "25" },
{ value: 50, text: "50" },
{ value: 100, text: "100" }

5 is the option by default. Can some one tell me how to save user selection (say 10) in a cookie so that next time 10 should be the pagesize

Answer Source

You can use ngCookies module of AngularJS. You'll have to include angular-cookies.js in your code:

Include ngCookies in your module declaration:

angular.module('testApp', ['ngCookies'])

Then you can save a cookie as:

$cookies.put('someKey', 'someVal');

You can retrieve a cookie as:


Updated: Check this fiddle:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download