使用 Angular UI 可排序时不执行自定义事件处理程序?
Custom event handler is not executed when using Angular UI Sortable?
我有如下一段代码:
<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>
和您的控制器:
$scope.sortableOptions = {
start: onDragStartHandler(e, ui)
};
因为 onDragStartHandler 是一个全局函数 - 请记住,您可能需要 $apply() 作用域才能看到绑定更新。
我有如下一段代码:
<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>
和您的控制器:
$scope.sortableOptions = {
start: onDragStartHandler(e, ui)
};
因为 onDragStartHandler 是一个全局函数 - 请记住,您可能需要 $apply() 作用域才能看到绑定更新。