Alan2
Alan2

Reputation: 24602

Is there anything in AngularJS that can help me get data to and from local storage?

Some of my user screens have select tags looking like this:

<select
   data-ng-disabled="option.subjects.length == 0"
   data-ng-model="option.selectedSubject"
   data-ng-options="item.id as item.name for item in option.subjects">
   <option style="display: none" value="">Select Subject</option>
</select>

Rather than show the "Select Subject" default, is there a good way that I could check local storage and retrieve a value for my select that was stored the last time I made a choice?

Upvotes: 0

Views: 522

Answers (1)

saada
saada

Reputation: 2781

Yes, check this one out. This is the best one I've found yet.
---> angular-local-storage

Here's a DEMO

Sample Code

var YourCtrl = function($scope, localStorageService, ...) { 
    // To add to local storage
    localStorageService.add('localStorageKey','Add this!');
    // Read that value back
    var value = localStorageService.get('localStorageKey');
    // You can also play with cookies the same way
    localStorageService.cookie.add('localStorageKey','I am a cookie value now');
}

Upvotes: 3

Related Questions