text: // install   :     cordova plugin add org.apache.cordova.device-orientation
  // link      :     https://github.com/apache/cordova-plugin-device-orientation/blob/master/doc/index.md
  
  angular.module('ngCordova.plugins.deviceOrientation', [])
  
    .factory('$cordovaDeviceOrientation', ['$q', function ($q) {
  
      return {
        getCurrentHeading: function () {
          var q = $q.defer();
  
          navigator.compass.getCurrentHeading(function (result) {
            q.resolve(result);
          }, function (err) {
            q.reject(err);
          });
  
          return q.promise;
        },
  
        watchHeading: function (options) {
          var q = $q.defer();
  
          var watchID = navigator.compass.watchHeading(function (result) {
            q.notify(result);
          }, function (err) {
            q.reject(err);
          }, options);
  
          q.promise.cancel = function () {
            navigator.compass.clearWatch(watchID);
          };
  
          q.promise.clearWatch = function (id) {
            navigator.compass.clearWatch(id || watchID);
          };
  
          q.promise.watchID = watchID;
  
          return q.promise;
        },
  
        clearWatch: function (watchID) {
          return navigator.compass.clearWatch(watchID);
        }
      };
    }]);
  