Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

LocalStorage paginated

$
0
0

Hello guys,

Contributing with more a tutorial, localStorage paginated:

 (function(){

     angular
        .module('started.app')
        .factory('LocalStorageTravel', LocalStorageTravel);

     function LocalStorageTravel(){

     var RESULT_BY_PAGE = 2;

     var services = {
       get: get,
       set: set,
       remove: remove,
       listar: listar
     }

    return services;

    function get(key) {
         return JSON.parse(localStorage.getItem(key));
     }

     function set(key, data) {
         localStorage.setItem(key, JSON.stringify(data));
    }

     function remove(key) {
         localStorage.removeItem(key);
     }

     function list(page) {

       var travels = [];

       var itemsLocalStorage = get('travels');

       var minResult = (page-1) * RESULT_BY_PAGE;
       var maxResult = page * RESULT_BY_PAGE;

       return itemsLocalStorage.slice(minResult, maxResult);

     }

}

})();

Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>