1
votes

I am new to ionic-framework, trying to implement shared prefrences in ionic platform for which cordovaPreferences is the plugin:

  • I downloaded plugin with cordova plugin add cordova-plugin-app-preferences
  • installed ngCordova
  • added ng-cordova.js in index.html before cordova.js
  • added ngCordova' in my starter module
  • injected $cordovaPreferences in controller

Then I am using:

$cordovaPreferences.store('key', 'myMagicValue')
  .success(function(value) {
     alert("Success: " + value);
   })
  .error(function(error) {
     alert("Error: " + error);
   })

But an alert is generated saying "Plugin not enabled":

Screen shot of error

Please Help.

3
You need to try to launch this in an emulator or a mobile device - Shijin TR

3 Answers

3
votes

ngCordova preferences object is a wrapped version of cordova app preferences plugin. I'm author of that plugin.

When you use preferences too early (before deviceready event), ngCordova will display alert window with "Plugin not enabled" message. Here is the code. Wait for deviceready event as Dirk D. suggests:

$ionicPlatform.ready (function () {
    // your code here
})

Another possibility why you see this alert is that you're trying to test your app in browser with ionic serve or cordova serve or cordova run browser, but browser platform is not available till plugin version 0.7.7 which I released today.

1
votes

You need to run this app in Android or iOS. Some plugins are not for the browser.

Following command is to add platform android

ionic platform add android

To build

ionic build android

To Emulate

ionic emulate android

If you are not satisfied with the emulation, after the build command, just go to YourApp'sFolder\platforms\android\build\outputs\apk and copy the apk file to your device and install

Check that the plugin is working successfully

0
votes

wrap your call into :

$ionicPlatform.ready(function() {

...

});