javascriptangularjsangular-ui-tree

Angular UI Tree Module: removed callback not working


I am using this module: https://github.com/angular-ui-tree/angular-ui-tree

And I can not make the removed callback work. Here is an example with an "accept" callback working, but "removed" not:

<div ng-controller="treeCtrl">
<div ui-tree="treeOptions">
  <ol ui-tree-nodes ng-model="rows">
    <li ng-repeat="row in rows" ui-tree-node>
      <div ui-tree-handle>
        {{row.name}}<a data-nodrag="" ng-click="remove(this)" href="#">X</a>
      </div>
    </li>
  </ol>
</div>

angular.module('treeApp', ['ui.tree'])

.controller('treeCtrl', function($scope) {

    $scope.treeOptions = {
        accept: function(sourceNodeScope, destNodesScope, destIndex) {
            return false;  
      },
      removed : function(node){
            alert('hey');  
      }
    };

    $scope.rows = [{"name": "node1"},{"name": "node2",},{"name": "node3"},{"name": "node4"}];

});

Demo: http://jsfiddle.net/4924U/68/

I could not find anything about it, is it a bug? Th


Solution

  • I ran into this same issue. A quick glance at the code for angular-ui-tree revealed that the callback is actually run by the removeNode() method which is the return for the remove method. I switched to using just removeNode() and my callbacks now function fine.

    So, try using removeNode(this).