Set focus on first invalid input in AngularJs form

前端 未结 13 1413
-上瘾入骨i
-上瘾入骨i 2020-12-04 18:55

I\'ve read several articles and StackOverflow questions relating to the setting of focus in AngularJs.

Unfortunately all the examples that I have read assume that th

相关标签:
13条回答
  • 2020-12-04 19:44

    just one line:

    if($scope.formName.$valid){
        //submit
    }
    else{
        $scope.formName.$error.required[0].$$element.focus();
    }
    
    0 讨论(0)
提交回复
热议问题