我有以下代码:
<ul ui-sortable ng-model="list">
<!-- onDragStartHandler() is a global function, not part of $scope -->
<li draggable ondragstart="onDragStartHandler();" ng-repeat="item in list">Item: {{item}}</li>
</ul>
当使用 ui-sortable
( github ) 指令时,附加到 ondragstart
的代码根本不会执行。
你可以看到这个here .
您知道如何调用此事件处理程序吗?
最佳答案
我的猜测是,ui-sortable 操纵 dom 并删除事件处理程序。
如果您look at their options - 您可以像这样连接到回调:
<ul ui-sortable="sortableOptions" ng-model="list">
<!-- onDragStartHandler() is a global function, not part of $scope -->
<li draggable ng-repeat="item in list">Item: {{item}}</li>
</ul>
和你的 Controller :
$scope.sortableOptions = {
start: onDragStartHandler(e, ui)
};
因为 onDragStartHandler 是一个全局函数 - 请记住,您可能需要 $apply() 范围才能查看绑定(bind)的更新。
关于javascript - 使用 Angular UI Sortable 时未执行自定义事件处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38312312/