在angularjs中选择选项和单选按钮验证

在angularjs中选择选项和单选按钮验证,angularjs,Angularjs,选择下拉菜单,单选按钮验证不起作用。请在下面查找代码。HTMLrequired选项已存在于标记中,但仍不起作用。我错过了什么 这是我的建议 var-app=angular.module('myApp',[]); 应用程序控制器('MainCtrl',函数($scope){ $scope.cityArray=[“海得拉巴”、“塞坎德拉巴德”、“德里”、“孟买”]; $scope.submit=函数($event){ if($scope.myForm.$invalid){ //或者其他更新 $sc

选择下拉菜单,单选按钮验证不起作用。请在下面查找代码。HTML
required
选项已存在于标记中,但仍不起作用。我错过了什么

这是我的建议


var-app=angular.module('myApp',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.cityArray=[“海得拉巴”、“塞坎德拉巴德”、“德里”、“孟买”];
$scope.submit=函数($event){
if($scope.myForm.$invalid){
//或者其他更新
$scope.myForm.$submitted=true;
$event.preventDefault();
}
}
});
登记表
登记表
名字:
名字不能少于3个没有数字的字母
请填写上面的字段

姓氏: 姓氏不能少于3个无数字的字母
请填写上面的字段
密码: 密码不能少于3个字母
请填写上面的字段
确认密码: 密码不能少于3个字母 请填写上面的字段

性别:女男

流动电话: 请输入有效的手机号码
请填写上面的字段
电邮: 无效的电子邮件地址
请填写上面的字段
地址: 地址不能为空 请填写上面的字段

街道: 请填写上面的字段

面积: 请填写上面的字段

城市: (挑一个) 请填写上面的字段

声明: 请填写上面的字段

国家: 请填写上面的字段

别针: 只允许使用六位数字 请填写上面的字段

提交
对于城市字段,为select标记指定一个名称,并在验证中运行该名称标记上的服务错误…即(myForm.sample.$error.required)

以下是下拉式验证的代码
(挑一个)
请填写上面的字段


对于城市字段,为select标记指定一个名称,并在验证中运行该名称标记上的服务错误…即(myForm.sample.$error.required)

以下是下拉式验证的代码
(挑一个)
请填写上面的字段

此处已更新

您忘记分配
名称
属性来选择并使用它显示错误:-

例如
name=“city”
并将其用于
ng if=“myForm.$submitted&&myForm.city.$error.required”

这里有更新

您忘记分配
名称
属性来选择并使用它显示错误:-

例如
name=“city”
并将其用于
ng if=“myForm.$submitted&&myForm.city.$error.required”


在单选按钮和城市下拉列表验证的情况下,您应该删除
$event.preventDefault()在控制器代码中。这彻底解决了问题

请参阅“工作”对话框“

为“性别”添加以下内容以在屏幕上显示消息,并将“名称”属性更改为一个通用值,如“性别”:


在单选按钮和城市下拉列表验证的情况下,您应该删除
$event.preventDefault()在控制器代码中。这彻底解决了问题

请参阅“工作”对话框“

为“性别”添加以下内容以在屏幕上显示消息,并将“名称”属性更改为一个通用值,如“性别”:

用这个

City:  <select name="dd" ng-model="citySelection" class="form-control" ng-options="city for city in cityArray" required>
                                                <option value="">(Pick One)</option>
                                            </select>
                                            <span style="color:red" class="error" ng-if="myForm.$submitted && myForm.dd.$error.required">Please fill field above<br></span><br/>
城市:
(挑一个)
请填写上面的字段

使用此

City:  <select name="dd" ng-model="citySelection" class="form-control" ng-options="city for city in cityArray" required>
                                                <option value="">(Pick One)</option>
                                            </select>
                                            <span style="color:red" class="error" ng-if="myForm.$submitted && myForm.dd.$error.required">Please fill field above<br></span><br/>
城市:
(挑一个)
City: <select name="city" ng-model="citySelection" class="form-control" ng-options="city for city in cityArray" required>
    <option value="">(Pick One)</option>
</select>
<span style="color:red" class="error" ng-if="myForm.$submitted && myForm.city.$error.required">Please fill field above<br></span><br/>
Gender: <input type="radio" name="gender" ng-model="color1" value="female" ng-required="!color1"/>Female <input type="radio" name="gender" ng-model="color1" value="male" ng-required="!color1"/>Male <br/><br/>
<span style="color:red" class="error" ng-if="myForm.$submitted && myForm.gender.$error.required">Please fill field above<br></span>
Gender: <input type="radio" name="gender" ng-model="color1" value="female" ng-required="!color1"/>Female <input type="radio" name="gender" ng-model="color1" value="male" ng-required="!color1"/>Male <br/><br/>

<span style="color:red" ng-show="myForm.gender.$error.require == true">Select Gender</span>
<span style="color:red" class="error" ng-if="myForm.$submitted && myForm.gender.$error.required">Please fill field above<br></span><br/>
City:  <select ng-model="citySelection" name = "city" class="form-control" ng-options="city for city in cityArray" required>
                                                <option value="">(Pick One)</option>
                                            </select>
<span style="color:red" ng-show="myForm.city.$error.require == true">city cannot be empty</span>

<span style="color:red" class="error" ng-if="myForm.$submitted && myForm.city.$error.required">Please fill field above<br></span><br/>
City:  <select name="dd" ng-model="citySelection" class="form-control" ng-options="city for city in cityArray" required>
                                                <option value="">(Pick One)</option>
                                            </select>
                                            <span style="color:red" class="error" ng-if="myForm.$submitted && myForm.dd.$error.required">Please fill field above<br></span><br/>