user1027620
user1027620

Reputation: 2785

Using ngCordova with Cordova App

I'm trying to use ngCordova for my cordova app however, I am getting device is undefined when calling the below:

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

app.controller('homeController', function ($scope, $cordovaDevice) {
    $scope.pageClass = 'page-home';
    $cordovaDevice.getPlatform(); // console.log or something.
    });

Everything is included correctly and the plugin is installed. What seems to be the problem?

Upvotes: 1

Views: 169

Answers (1)

unobf
unobf

Reputation: 7244

You need to wait for the deviceready event before accessing any of the ngCordova plugins

document.addEventListener("deviceready", function () {
  $cordovaDevice.getPlatform();
}, false);

Upvotes: 1

Related Questions