How to dynamically disable ui-sortable directive in angular-ui

后端 未结 4 1510
野趣味
野趣味 2021-02-13 01:41

I am using angular-ui for sortable using ui-sortable directive. Is it possible to dynamically enable/disable sortable functionality based on the scope state? So I need to have a

4条回答
  •  花落未央
    2021-02-13 02:15

    The angular directive supports watching when the sortable options change:

    scope.$watch(attrs.uiSortable, function(newVal, oldVal){
    

    So all you had to do was look at the jqueryui sortable documentation, and update the correct property on the plugin.

    Html

    • {{ item }}

    JS

    app.controller('MainCtrl', function($scope) {
      $scope.items = ["One", "Two", "Three"];
    
      $scope.sortableOptions = {
        disabled: true
      };
    });
    

提交回复
热议问题