【发布时间】:2017-02-03 22:20:03
【问题描述】:
我试图在每次对象的 $index 更改时调用一个 ng-change 函数。对象是可以在屏幕上重新排序的可拖动 div 列表。
索引是对象的位置,每次更改时我都需要更新 api,这不是我遇到问题的部分。
当 $index 值发生变化时,它会通过 ng-change 实际调用函数。有什么建议吗?
<div class="col s7 offset-s1 tooltipped" data-position="bottom" data-delay="50" data-tooltip="Drag cards to move their position.">
<form id="dashDragForm">
<div class="card-panel hoverable center-align"
**ng-model="$index" ng-change="positionUpdate(current, $index)"**
ng-class="{'draggable-md': dashboard.Panels.length < 5 ,'draggable-sm': dashboard.Panels.length > 4}"
ng-repeat="current in dashboard.Panels">
<div class="row col-s12">
<i ng-if="current.Type == 'Table'" class="material-icons left white-text">line_style</i>
<i ng-if="current.Type == 'Chart'" class="material-icons left white-text">timeline</i>
<i class="close material-icons right modal-trigger" data-target="removePanelModal" ng-click="openDeleteModal(current, $index)">close</i>
</div>
<h6 class="white-text">{{current.Title}}</h4>
<div class="row col-s12">
<br/>
</div>
</div>
</form>
</div>
【问题讨论】:
-
你能创建一个 jsfiddle 吗?或提供完整代码?
-
抱歉,我不确定这个描述的问题出在哪里
-
一个 jsfiddle 并没有真正的帮助。我需要在索引更改时调用 ng-change 函数,而这并没有发生..
-
索引如何变化?无论如何?或者你想在 ng-repeat 循环中调用 ng-change ?
-
我很确定文档说每次模型更改该对象时都应该调用 ng-change ,但这并没有发生,这就是问题所在。 :) 每次有人在屏幕上移动对象时,索引都会更改,因为 ng 重复的对象是可拖动的
标签: javascript angularjs indexing angularjs-directive