1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| var module = angular.module('numberApp', []);
module.controller('NumberController', function($scope, $timeout) {
(function update() {
var x = $timeout(update, 1000 * 1);
$scope.randomNumber = Math.floor(Math.random()*($scope.max-$scope.min+1)+$scope.min);
}());
$scope.getInput = function() {
if($scope.min > $scope.max) {
//Swap variables
[$scope.min,$scope.max] = [$scope.max,$scope.min];
}
$scope.generateNumber();
}
$scope.loadNum = function() {
$scope.min = 1;
$scope.max = 1000000;
$scope.generateNumber();
}
$scope.generateNumber = function() {
$scope.randomNumber = Math.floor(Math.random()*($scope.max-$scope.min+1)+$scope.min);
}
}); |
Partager