77790

How to use ionic cordova preferences?

Question:

Currently I'm using <a href="http://ngcordova.com/docs/plugins/preferences/" rel="nofollow">cordova app preferences</a> to store some data with today's date as key.

var pref = $cordovaPreferences.fetch(date, 'dates').$$state.status; if (pref===0) { var out = $cordovaPreferences.store(date, '1', 'dates'); dbPopup('store' + JSON.stringify(out));

}

But both the fetch and store methods always displays the status as 0. I didn't uninstall my app for every time. Since uninstallation of app removes the stored preferences..

Answer1:

I would recommend using $window.localStorage. It also uses keys to save strings. You can use JSON.stringify to convert objects to a string.

An example can be found here: <a href="http://codepen.io/drewrygh/pen/ciozB" rel="nofollow">http://codepen.io/drewrygh/pen/ciozB</a>

Recommend

  • Saving JSON object in CouchDB from JavaScript
  • Converting Uint8Array crashing browser for large files
  • Unhandled Rejection: Headers cant be set after they are sent
  • React Native Fetch does not render response until after clicking screen
  • jQuery Datatable: pagination and filter not display correctly
  • How to send json data form jQuery?
  • JQuery Mobile POST data empty in $_POST
  • how to send the response to browser fromm http.request in node.js?
  • Scope issues in my Angular factory code
  • How to send http post call from node server?
  • Javascript remove duplicate values from array of objects
  • Websocket across pages JavaScript
  • Can I return raw json response in angular2
  • Cannot read property setState of undefined in axios callback
  • Google script gmail addon update TextInput value,on change function
  • Get Quarters StartDate and EndDate from Year
  • MS SQL Server 2008 :Getting start date and end date of the week to next 8 weeks
  • toString() for each element of an array in Javascript [duplicate]
  • JavaScript - Can we set javascript objects in cookies?
  • Function insertMany() unordered: proper way to get both the errors and the result?
  • Aggregating two data frame columns without any existing pattern logic
  • data.table replicate rows after join?
  • CSS - Cannot get one spanned style to override another inherited style and align left
  • How Get arguments value using inline assembly in C without Glibc?
  • SQL Query - Table Joining Problems
  • Can't remove headers after they are sent
  • How to make R's read_csv2() recognise the text characters properly
  • JPA flush vs commit
  • Suppressing passwd when calling sqlplus from shell script
  • Implementation of State Monad
  • How to use JavaScript to determine whether a file exists in a directory?
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Why is the size of this struct 32?
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • htaccess rewriting URLs with multiple forward slashes
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Cannot Parse HTML Data Using Android / JSOUP
  • C# - Getting references of reference
  • Is it possible to post an object from jquery to bottle.py?