driftyco/ng-cordova — pull request #90 by rbecheras (2014-06-20 20:09:58+00:00)
Title: Passing the watchID throw the resolve method

I just added the watchID local variable to handle the return of watchAcceleration().
Then the promise factory resolve the method passing the watchID to the controllers, this one is required to use clearWatch(id).

So you can update the documentation like this :

module.controller('DeviceMotionCtrl', function($scope, $cordovaDeviceMotion) {
$scope.getAcceleration = function () {
$cordovaDeviceMotion.getCurrentAcceleration().then(function(result) {
// Success!
}, function(err) {
// An error occured. Show a message to the user
});
};

$scope.watchAcceleration = function () {
var options = { frequency: 3000 }; // Update every 3 seconds

var watchID = $cordovaDeviceMotion.watchAcceleration(options).then(
function(watchID) {
// handle the watchID to use it with clearWatch()
},
function(err) {},
function(acceleration) {
$cordovaDialogs.alert('Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
});
};

$scope.clearWatch = function() {
// use watchID from watchAccelaration()

$cordovaDeviceMotion.clearWatch(watchID).then(function(result) {
// Success!
}, function(err) {
// An error occured. Show a message to the user

});
}
});