angularjs - Alert() twice in simple angular app -


alert function firing off twice, can't figure out why: http://jsfiddle.net/ntzlrkmz/2/

it's going alert when !number inserted @ <input type="number">

edit: all, i'll playing useful information

this happens because angular evals list when times variable change , $diggest build ng-reapeat new value. should use $watch instead:

angular.module('helloapp', [])     .controller('hellocontroller', ['$scope', function ($scope) {     $scope.times = 1;     $scope.$watch('times', function (newvalue, oldvaue) {         if (!angular.isnumber(newvalue)) {             $scope.times = oldvaue;             alert('enter valid positive number please');         }     });      $scope.gettimes = function (n) {         if (angular.isnumber(n)) {             return new array(n);         }     }; }]); 

working example here: http://jsfiddle.net/fals/75uv4ugb/


Comments

Popular posts from this blog

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -