I want to disable my button but then activate it a few seconds later. The code does run but the button is still disabled even after my code has executed.
app.controller('spamController', ['$scope', function($scope) {
$scope.stopSpam = false;
function activateBtn(){
$scope.stopSpam = false;
};
$scope.test = function(){
$scope.stopSpam = true;
activateBtn();
};
}]);
<button ng-disabled="stopSpam" class="btn btn-default" ng-click="test()">Test</button>
答案 0 :(得分:3)
Use $timeout
and call activateBtn
after a few seconds:
app.controller('spamController', ['$scope', '$timeout', function($scope, $timeout) {
$scope.stopSpam = false;
function activateBtn(){
$scope.stopSpam = false;
};
$scope.test = function(){
$scope.stopSpam = true;
$timeout(activateBtn, 3000);
};
}]);