JSFiddle - React, Tailwind, and code Playground
by Aaron Zhang
HTML
<div ng-app="myApp">
<div ng-controller="myController">
<button ng-click="cancelPromise()">Cancel Promise</button>
</div>
</div>
JavaScript
(function () {
'use strict';
var app = angular.module('myApp', []);
app.controller('myController', ['$scope', '$timeout', function ($scope, $timeout) {
var timeoutPromise = $timeout(function () {
return 'message';
}, 5000);
timeoutPromise.then(function (value) { //resolved
alert(value);
},function(reason){ //rejected
alert('Rejected: ' + reason);
});
$scope.cancelPromise = function(){
if($timeout.cancel(timeoutPromise) === true){
alert('Successfully Terminated!');
}else{
alert('Termination Failed!');
}
};
}]);
})();