Please see my code snippet.
<!DOCTYPE html>
<html data-ng-app="myApp">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
</head>
<body data-ng-controller="testController">
<ng-form name="phoneInnerForm">
<div>
<div class="form-group" data-ng-repeat="item in items" ng-class="phoneInnerForm.phones{{$index}}.$error.maxlength ? 'phone_number_error': ''">
<input type="text" class="form-control" id="InputAddPhone" name="phones{{$index}}" ng-model="item.number" ng-maxlength="50">
<select class="form-control" ng-model="item.type">
<option value=""></option>
<option value="mobile">Mobile</option>
<option value="work">Work</option>
<option value="home">Home</option>
<option value="fax">Fax</option>
<option value="other">Other</option>
</select>
<div class="evy_email_dltbtn">
<button type="button" class="btn btn-default btn_delete" ng-click="deleteItem($index);" title="Delete">Delete</button>
<button ng-show="$last" type="button" class="btn btn-default btn_delete" ng-click="addItem();" title="Delete">Add</button>
</div>
<span ng-show="phoneInnerForm.phones{{$index}}.$error.maxlength" class="evy_user-preference_error">Phone number should not exceed 50 characters</span>
</div>
</div>
</ng-form>
<script>
angular
.module('myApp', [])
.controller('testController', ['$scope',
function($scope) {
$scope.items = [{
number: "",
type: ""
}];
$scope.addItem = function() {
$scope.items.push({
number: "",
type: ""
});
}
$scope.deleteItem = function(index) {
$scope.items.splice(index, 1);
}
}
]);
</script>
</body>
</html>
try adding 3-4 phone numbers having length greater than 50. Then try removing first phonenumber using delete button. Now see my issue , That is last phone numbers validation is removed. Please help me.