Add double click event on child node in angular-tree-widget
I am new to angular-tree-widget.js. We need to implement a double click event when we click on any child tree of the tree node. Everything I've found only supports two events.
$scope.$on('selection-changed', function (e, node) {
//node - selected node in tree
$scope.selectedNode = node;
});
$scope.$on('expanded-state-changed', function (e, node) {
// node - the node on which the expanded state changed
// to see the current state check the expanded property
//console.log(node.expanded);
$scope.exapndedNode = node;
});
How do I add a double click event on a node here? Please help me. Thanks in advance.
+3
source to share
1 answer
You can add ng-dblclick
as @Manikandan suggested like this:
Html
<body ng-controller="TreeController" ng-dblclick="dblclick($event)">
<tree nodes='treeFamily'></tree>
</body>
JavaScript
controller('TreeController', ['$scope', function ($scope) {
$scope.dblclick = function(evt) {
angular.element(evt.target).toggleClass('red')
}
...
}])
Live Demo
https://plnkr.co/edit/nWfiDA82WDpgRGnLqJUs?p=preview
As you can see, the idea is to subscribe to the event on the parent of the tree and distinguish between the tree elements with evt.target
which is passed to the event handler using angular$event
+1
source to share