-2

I want to validate a element which is genegrated by ng-repeat at script section

<form name="form">
<div ng-repeat=".......">
    <input type="text" name="test{{$index}}"/>
    <input type="button" ng-click="Check($index)"/>
</div> 
</form>

<script>
var Check = function Check(index) {
    //How can i check this element valid 
    //All i want to do like this: $scope.form.test{{index}}.$valid
   //It doesn't understand $scope.form.test{{index}}.$valid
    if ($scope.form.test{{index}}.$valid) 
    { 
        //do something
    }
}
</script>

Can anyones help me. Thanks

Anh Tuan
  • 7
  • 2
  • 1
    possible duplicate of [Dynamically access object property using variable](http://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable) – Blackhole Jan 09 '15 at 13:59

1 Answers1

0

Use the bracket notation:

if ($scope.form['test' + index].$valid) { }
Blackhole
  • 20,129
  • 7
  • 70
  • 68