I'm using AngularJS to validate a form, and I have this button to submit.
<button type="submit" ng-disabled="btn" ng-click="submit(settings.$valid)"
class="btn btn-primary">
Submit
</button>
This button is disabled whenever the form is invalid, but once it's valid, the button is enabled.
So this is my code
$http.get("http://localhost:5000/settings").then(function(response){
$scope.numberOfRows = response.data.numberOfRows
console.log($scope.numberOfRows)
if($scope.numberOfRows==0 && $scope.settings.$valid == false ){
$scope.btn=true
}else if($scope.numberOfRows==0 && $scope.settings.$valid == true){
$scope.btn=false
}
if($scope.numberOfRows==1){
$scope.btn=true
}
})
My problem is when the numberOfRows = 0 and the form is invalid, I can't submit the form which what I want.
BUT, when I fill my form and it became valid, nothings happend.
Can you help me ?
{{btn}}in the html, and doconsole.log($scope.numberOfRows, $scope.settings.$valid)inside the function you gave!ng-disabled="validate()"for the button and move the if statements inside the validate function, this will calculate continuously, I think that your function is checking the conditions only once.