【问题标题】:Validate current element which is genegrated by ng-repeat angularjs at jsfile验证由 ng-repeat angularjs 在 jsfile 生成的当前元素
【发布时间】:2015-01-09 21:58:33
【问题描述】:

我想验证由 ng-repeat 在脚本部分生成的元素

<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>

谁能帮帮我。谢谢

【问题讨论】:

标签: angularjs ng-repeat


【解决方案1】:

使用bracket notation

if ($scope.form['test' + index].$valid) { }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多