question about $interval.cancel
Hi All,
I want to achieve such an effect through $interval: when I click button A, Call function GunTongstartRotate, the model starts to rotate continuously; when I click button B,Call function GunTongstopRotate, the model stops rotating. The following is the code I wrote.
$scope.GunTongRotate = function() {
$scope.app.params.QMJrx = $scope.app.params.QMJrx-5;
};
$scope.GunTongstartRotate = function() {
//store the interval promise
$scope.app.params.QMJrx=0;
intervalPromise = $interval($scope.GunTongRotate, 50, 0);
};
$scope.GunTongstopRotate = function() {
if(angular.isDefined(intervalPromise)){
$interval.cancel(intervalPromise);
$scope.app.params.QMJrx=0;
}
};
The problem is that when I click button A multiple times, the model will turn faster and faster, and clicking button B again will not stop the model from turning. How should I solve this problem?

