Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Felipe Cruz 6 posts 86 karma points
    Jul 22, 2016 @ 09:40
    Felipe Cruz
    0

    Get selected node when clicking (AngularJS)

    Hi,

    In my custom section I am trying to get in AngularJS the active node when clicking straightforward on the three dots button - please note that I am not clicking on the name of the item:

    enter image description here

                var activeNode = appState.getTreeState("selectedNode");
    

    However I get null as the item has not been actually selected (you can see it is not highlighted in blue color).

    Is this a bug or is there any other way to get the selected node when clicking on the three dots button?

    Thank you very much!

  • Ian 178 posts 752 karma points
    Jul 22, 2016 @ 11:44
    Ian
    0

    Can you post the 'outer' code to provide some context of where you are when trying to do this i.e an angular controller for the dashboard of the section / an edit view for a node or within a controller for the dialog panel.

    If you are in the dialog you can do this.

    var currentNode = $scope.dialogOptions.currentNode
    
  • Ian 178 posts 752 karma points
    Jul 22, 2016 @ 12:38
    Ian
    0

    In my version of umbraco there is also this, an event is triggered when clicking on the dots..

    (inside umb-tree diretive)

    emitEvent("treeOptionsClick", { element: elem, node: n, event: ev });
    

    Maybe in what ever controller you are using you could inject eventsService then..

    eventsService.on("treeOptionsClick", function (e, args) {
            //set selected node in your scope from args
        })
    
  • Felipe Cruz 6 posts 86 karma points
    Jul 22, 2016 @ 13:19
    Felipe Cruz
    0

    Thanks Ian, in my version of Umbraco I can see the emitEvent in the umbraco.directives.js file (line 2910).

    However, when I inject the eventsService in my controller the treeOptionsClick event does not get fired...

  • Felipe Cruz 6 posts 86 karma points
    Jul 22, 2016 @ 13:36
    Felipe Cruz
    0

    Some simplistic code:

    The view:

    <div ng-controller="CatalogueDashboard.Controller"></div>
    

    The controller:

    angular.module("umbraco").controller("CatalogueDashboard.Controller",
    function ($scope, eventsService) {
    
        eventsService.on("treeOptionsClick", function (e, args) {
            // this never gets fired
        });
    });
    
  • Ian 178 posts 752 karma points
    Jul 22, 2016 @ 22:04
    Ian
    100

    OK after some more digging treeOptionsClick does not get sent to the events service only from the tree directive to the tree controller.

    However this should work for you

    eventsService.on("appState.menuState.changed", function (e, args) {
            //set selected node in your scope from args
            console.log(args)
        })
    
Please Sign in or register to post replies

Write your reply to:

Draft