我试图找到在文本框中输入的重复值,该值检查 ng-change 上的每个输入值。然后显示消息“sos 编号匹配”。尝试了这个,但仍然按顺序对列表数据进行排序。 结果,到目前为止,我没有成功发送常规消息jsfiddle 。以下是代码。:
html代码:
<form name="settingForm" ng-submit="mangeDeviceSettings()"><div class="form-group">
<div data-ng-repeat="i in sosLength track by $index">
<ng-form name="sosNumForm">
<span class="input-icon"> <input type="text" ng-disabled="!showPendingStatus" watch-change="change()"
class="form-control" name="SOSNumber" ng-minlength="10" ng-maxlength="13" placeholder="SOSNumber{{$index+1}} No." ng-pattern="/^[0-9]+$/"
ng-model="deviceSettings.sos[$index]" ng-change="sosChange($index,this)">
<i class="fa fa-mobile"></i></span>
<span ng-show="IsMatch{{$index}} && sampleSOS && sosNumForm.SOSNumber.$dirty">SOS Number has a match!</span>
<span ng-show="(sosNumForm.SOSNumber.$error.minlength || sosNumForm.SOSNumber.$error.maxlength) && sosNumForm.SOSNumber.$dirty">Mobile Number must be between 10 and 13 digits </span>
<span ng-show="!sosNumForm.SOSNumber.$error.minlength && !sosNumForm.SOSNumber.$error.maxlength && sosNumForm.SOSNumber.$error.pattern && sosNumForm.SOSNumber.$dirty">Number must contain only numbers</span>
</ng-form>
</div>
</div>
</div></form>
ng-change 方法:
$scope.sosChange=function(idx, obj){
$scope.sampleSOS = true;
$scope.fnfDuplicate=true;
obj.$parent.settingForm.$valid = obj.sosNumForm.$valid;
// console.log(obj.$parent.settingForm.$valid);
// console.log(obj.sosNumForm.$valid);
console.log($scope.deviceSettings.sos[idx]);
console.log($scope.deviceSettings.sos[i] );
// console.log(obj.sosNumForm.$valid);
// console.log($scope.deviceSettings.sos[idx]!="");
for (var i = 0; i < 3; i++) {
if(idx != i ){
if ($scope.deviceSettings.sos[idx] == $scope.deviceSettings.sos[i]
&& obj.sosNumForm.$valid && $scope.deviceSettings.sos[idx]!="") {
if(idx==0){
$scope.IsMatch0=true; $scope.sosDuplicate=true;
return false;
}
if(idx==1){
$scope.IsMatch1=true; $scope.sosDuplicate=true;
return false;
}
if(idx==2){
$scope.IsMatch2=true; $scope.sosDuplicate=true;
return false;
}
}
else{
if(idx==0){
$scope.IsMatch0=false; $scope.sosDuplicate=false;
return false;
}
if(idx==1){
$scope.IsMatch1=false; $scope.sosDuplicate=false;
return false;
}
if(idx==2){
$scope.IsMatch2=false; $scope.sosDuplicate=false;
return false;
}
}
// $scope.sosDuplicate=true;
}
}
}