Software Archive
Read-only legacy content
17061 Discussions

Cordova's plugins dont work in Ionic Layout Project

Douglas_N_
Beginner
284 Views

First I want to say I'm surprised with the features of XDK and thank Intel for this :)

So, I created a Ionic Layout Project following: Start a New Project -> Templates -> Layout and User Interfaces -> Ionic Framework Starter.

Now I'm trying to add Cordova Plugins using ngCordova, but is not working on real devices.

For example, my app.js:

var app = angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicPlatform, $cordovaSQLite) {
    $ionicPlatform.ready(function() {
        if(window.cordova && window.cordova.plugins.Keyboard) {
            // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            // for form inputs)
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

            // Don't remove this line unless you know what you are doing. It stops the viewport
            // from snapping when text inputs are focused. Ionic handles this internally for
            // a much nicer keyboard experience.
            cordova.plugins.Keyboard.disableScroll(true);
        }
        
        if(window.StatusBar) {
            StatusBar.styleDefault();
        }
    });
});

Is showing this error:

Uncaught TypeError: Cannot read property 'Keyboard' of undefined

If I try to use plugins like SQLite, errors happens too.

But, if I run the app on Google Chrome, everithing works fine, also the SQLite with WebSQL.

0 Kudos
3 Replies
Douglas_N_
Beginner
284 Views

I cant edit the post, so I will add information in the comments.

I tried to add the plugin in two ways, first manually and then via the command line. Following this guides

$cordova plugin add ionic-plugin-keyboard
--and--
$cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git

To be able to use the cordova commands, I created /config.xml file and /plugins folder manually.

0 Kudos
PaulF_IntelCorp
Employee
284 Views

To add a plugin use the XDK you use the "plugin management tool" on the Projects tab. That template that you chose to use is a "standard HTML5" template which doesn't include the ability to add plugins. You must "convert" it into a Cordova app. See these instructions > https://software.intel.com/en-us/xdk/docs/using-the-projects-tab#upgradetocordova <

0 Kudos
Douglas_N_
Beginner
284 Views

Thanks for the tip. With the project upgrade the plugins are working now and the project structure is good.

If I start directly a new Project using Cordova + HTML5 and Ionic, the structure seems strange.

0 Kudos
Reply