Well, I'm working on a small project made in ionic. I'm using ngCordova to add some cool plugins, like device orientation for compass. But I can't force it to work. I already installed ngCordova and added plugins (geolocation plugin works). I'm out of ideas why this doesn't work.
Code looks like this:
.controller('GeoLocationCtrl', function($scope, $cordovaGeolocation, $cordovaDeviceOrientation, $ionicPlatform, $document) {
$scope.lat = 0;
$scope.long = 0;
$scope.position = {};
$ionicPlatform.ready(function() {
var options = {frequency: 1000}; // Update every 1 second
var watch2 = $cordovaDeviceOrientation.watchHeading(options); ///LINE 53!
watch2.promise.then(function (result) { /* unused */
},
function (err) {
// An error occurred
}, function (position) {
// Heading comes back in
// position.magneticHeading
$scope.position = position.magneticHeading;
});
$cordovaDeviceOrientation.clearWatch(watch2.watchId)
.then(function (result) {
// Success!
}, function (err) {
// An error occurred
});
});
})
But all I get is this:
ripple.js:37
TypeError: Cannot read property 'watchHeading' of undefined
at Object.watchHeading (http://localhost:8080/lib/ngCordova/dist/ng- cordova.min.js:1:14565)
at http://localhost:8080/js/controllers.js:53:44
at http://localhost:8080/lib/ionic/js/ionic.bundle.js:37388:19
at Object.ionic.Platform.ready (http://localhost:8080/lib/ionic/js/ionic.bundle.js:1915:9)
at Object.self.ready (http://localhost:8080/lib/ionic/js/ionic.bundle.js:37386:26)
at new <anonymous> (http://localhost:8080/js/controllers.js:15:20)
at invoke (http://localhost:8080/lib/ionic/js/ionic.bundle.js:11591:17)
at Object.instantiate (http://localhost:8080/lib/ionic/js/ionic.bundle.js:11602:23)
at http://localhost:8080/lib/ionic/js/ionic.bundle.js:14906:28
at updateView (http://localhost:8080/lib/ionic/js/ionic.bundle.js:42986:30) ionic.bundle.js:17696
Thanks for any help!