I'm trying to match two randomly generated numbers. I want to add ng-invalid class if result wrongly enter. In the controller this function is generating the numbers.
AngularJs
$scope.getRandomSpan = function(){
return Math.floor((Math.random()*6)+1);
}
HTML
<span ng-init="a=getRandomSpan()">{{ a }}</span>
<span ng-init="b=getRandomSpan()"> + {{ b }}</span>
I want to validate the numbers once user enter number in input field.
<input type="number" ng-model="captcha" required />
For example function generate two numbers 2 and 3 (equal to 5), now i want to add ng-invalid class if entered number not equal to 5. I have done this task in the controller which is validating after submit the form.
var random = $scope.a + $scope.b;
var enteredcaptcha = $scope.captcha;
if(random == enteredcaptcha){...}
But i don't know how to validate on the spot, can any one guide me about this I will appreciate. Thank You for guideline