我对angularjs非常陌生。假设我的应用程序有一个表单。使用检查器时,我注意到如果angularjs认为表单无效,它会向表单添加一个ng-invalid类。可爱的。
所以为了检查表单是否有效,我需要用Jquery选择器污染我的代码?!在不使用表单控制器的情况下,表明表单有效性的角度方法是什么?
发布于 2014-10-01 18:18:54
示例
<div ng-controller="ExampleController">
<form name="myform">
Name: <input type="text" ng-model="user.name" /><br>
Email: <input type="email" ng-model="user.email" /><br>
</form>
</div>
<script>
angular.module('formExample', [])
.controller('ExampleController', ['$scope', function($scope) {
//if form is not valid then return the form.
if(!$scope.myform.$valid) {
return;
}
}]);
</script>
发布于 2015-09-27 02:20:50
您也可以使用myform.$invalid
例如。
if($scope.myform.$invalid){return;}
https://stackoverflow.com/questions/14299834
复制相似问题