小编STE*_*TEP的帖子

ng-repeat 中的 $index 删除后未更新

情况

在图像上你可以看到我想要做什么。单击时,使用ng-repeat动态添加一行输入字段。+step删除x一个步骤并将up and down arrows步骤向上或向下移动一位。
我希望当台阶不能走高时禁用向上箭头,当台阶不能走低时禁用向下箭头。到目前为止,当我只添加步骤(而不是删除)时,它工作得很好。然而,当我删除一个步骤时,尽管在打印时它似乎$index已更新,但不知何故并未更新。ng-disabled

问题

这是删除第一步后得到的结果: image
如您所见,向下数组被禁用。虽然打印的索引是0,但是里面的索引ng-disabled一定还是1。

HTML:

<div class="col-sm-2 nopadding">
    <div class="btn-group btn-lg" role="group">
        <!--move step up-->
        <button type="button" class="btn iconbutton  " ng-click="" ng-disabled="{{$index}}==0"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span> 
        </button>
        <!--move step down-->
        <button type="button" class="btn iconbutton " ng-click="" ng-disabled="{{$index}}==normal.length-1"><span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span> 
        </button>
        <!--remove step-->
        <button type="button" class="btn iconbutton " ng-click="removeStep(step,'normal',0)"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 
        </button>
    </div>
    <p>index={{$index}}, length= {{normal.length}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)

删除控制器中的功能:

$scope.removeStep = …
Run Code Online (Sandbox Code Playgroud)

indexing dynamic angularjs

2
推荐指数
1
解决办法
1788
查看次数

标签 统计

angularjs ×1

dynamic ×1

indexing ×1