You can also use angular.element
angular.element('input.ng-invalid').first().focus();
View
<form name="myForm" novalidate="novalidate" data-ng-submit="myAction(myForm.$valid)" autocomplete="off"></form>
Controller
$scope.myAction= function(isValid) {
if (isValid) {
//You can place your ajax call/http request here
} else {
angular.element('input.ng-invalid').first().focus();
}
};
used ngMessages for validation
The no jquery way
angular.element($document[0].querySelector('input.ng-invalid')).focus();
When using this method, need to pass $document
as parameter in your angular controller
angular.module('myModule')
.controller('myController', ['$document', '$scope', function($document, $scope){
// Code Here
}]);