我提到了Angular JS Form validation inside tabset give error : TypeError: Cannot read property '$valid' of undefined但这并不正是我所寻找的。
我有这个 html 代码,
<form name="userForm" ng-submit="submit()" novalidate>
<input type="text" class="form-control" ng-model="user.name" required>
<button type="submit" class="btn btn-primary" ng-disabled="!userForm.$valid">Submit</button>
</form>
我的 js 是这样的,
$scope.submitForm = function () {
// check to make sure the form is completely valid
if ($scope.userForm.$valid) {
alert('its working');
}
};
我收到此错误。使用 ng-submit 时有办法解决这个问题吗?
最佳答案
您可以尝试一下下面的代码吗:
$scope.submitForm = function() {
// check to make sure the form is completely valid
if (userForm.$valid) {
alert('its working');
}
};
我从 $scope.userForm.$valid
中删除了 $scope
,因为 userForm 不是 $scope
的属性。
你可以查看AngularJS官方文档,especially this part ,您可以在其中查看它们如何绑定(bind)到表单。
关于javascript - 类型错误 : Cannot read property '$valid' of undefined on using ng-submit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38301366/