0
我有一个创建指南针的离子ngCordova应用程序。它工作正常,但我呼吁clearWatch()不做任何事情。
我有两个按钮的模板:
<ion-view title="Compass Page">
<ion-content>
<button class="button" ng-click="startCompass()">Start</button>
<button class="button" ng-click="stopCompass()">Stop</button><br>
{{dir}}
</ion-content>
</ion-view>
该控制器被如下:当我按下启动按钮和{{DIR}}值
angular.module('starter')
.controller('CompassCtrl', function($scope, $cordovaDeviceOrientation) {
$scope.dir = 0;
$scope.startCompass = function() {
var options = {
frequency: 500
};
$scope.watchId = $cordovaDeviceOrientation.watchHeading(options)
.then(
null,
function(error) {
console.log(error);
},
function(result) {
$scope.dir = result.trueHeading;
}
);
};
$scope.stopCompass = function() {
$cordovaDeviceOrientation.clearWatch($scope.watchId);
};
});
指南针启动细在我旋转设备时更新。我打电话给clearWatch什么都不做。
任何指针,我做错了将不胜感激。
艾丹