Search code examples
angularjsionic-frameworkcordova-plugins

How can I use SharedPreferences in Ionic?


I Downloaded the plugin from http://ngcordova.com/docs/plugins/preferences/

Copied AppPrefrences.js to /js folder,

passed $cordovaPreferences in my AppCtrl

but getting error:

Unknown provider: $cordovaPreferencesProvider <- $cordovaPreferences

How to implement Cordova preferences?


Solution

  • You need to install and include ngCordova as well

    http://ngcordova.com/docs/install/

    Get the Source File

    You can use bower to install ngCordova like so or download the zip file here, and locate the .js file in the dist folder:

    $ bower install ngCordova
    

    Include ng-cordova.js or ng-cordova.min.js in your index.html file before cordova.js and after your AngularJS / Ionic file (since ngCordova depends on AngularJS).

    <script src="lib/ngCordova/dist/ng-cordova.js"></script>
    <script src="cordova.js"></script>
    

    Inject as an Angular dependency

    Then, include ngCordova as a dependency in your angular module:

    angular.module('myApp', ['ngCordova'])