Angular Single and Double Click
JS
S
JavaScriptSimultaneous listeners (note: browser is slower detecting double clicks)
1 onTreeClick(tree: Tree): void {
2 this.dblClickControlTimer = setTimeout(() => {
3 this.selectAction(tree);
4 }, 300);
5 }
6
7 onTreeDoubleClick(tree: Tree): void {
8 clearTimeout(this.dblClickControlTimer);
9 this.dblClickControlTimer = undefined;
10 this.editAction(tree);
11 }
12
13 selectAction(tree: Tree): void {
14 if (!this.dblClickControlTimer) return;
15 this.selected.emit(tree);
16 this.selectedTree = tree;
17 console.log('selected');
18 }
19
20 editAction(tree: Tree): void {
21 this.edited.emit(tree);
22 console.log('edited');
23 }Created on 6/21/2020