我有一个问题。我在使用Angular.js时收到错误的验证消息。我在下面解释我的代码。
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Member Type :</span>
<select class="form-control" id="nosofvoucher" ng-model="vouchers" ng-options="v.name for v in listOfMember track by v.value " ng-change="generateCodeRange('nosofvoucher')" ng-disabled="dismember">
</select>
</div>
我的控制器端代码如下所示。
$scope.listOfMember=[{
name:'Select member type',
value:''
}]
$scope.vouchers=$scope.listOfMember[0];
$http({
method:'GET',
url:"php/selectMemberType.php",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
//console.log('respo',response.data);
angular.forEach(response.data,function(obj){
var data={'name':obj.member_name,'value':obj.member_type};
$scope.listOfMember.push(data);
})
$timeout(function(){
var value={'name':'New Registered User','value':0};
$scope.listOfMember.push(value);
},2000)
},function errorCallback(response) {
})
但是当我检查验证消息时,即使我从下拉列表中选择New Registered User
,验证消息仍然是Please add member type
,代码如下所示。
$scope.addGenerateCodeData=function(billdata){
if($scope.vouchers.value==null || $scope.vouchers.value==''){
alert('Please add member type');
codeFieldFocus.borderColor('nosofvoucher');
}
}
这里甚至在从列表中选择New Registered User
后,上面的验证消息正在执行,但不应该这样做。请帮我解决这个问题。