Copied to clipboard

Flag this post as spam?

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


  • K.Garrein 164 posts 629 karma points
    Oct 07, 2015 @ 08:02
    K.Garrein
    0

    Passing data to angularjs controller from MenuItem

    Hello again :)

    Is it possible to pass data from a MenuItem to an angularjs controller?

    Example:

     MenuItem mi = new MenuItem( "productcategories-edit","New product category" );
     mi.Icon = "icon icon-add";
     mi.AdditionalData.Add( "parent", "0" );            
     menu.Items.Add( mi );
    

    How do I retrieve the "AdditionalData" in the angularjs controller?

    Thanks. Kris.

  • K.Garrein 164 posts 629 karma points
    Oct 07, 2015 @ 11:48
    K.Garrein
    0

    Maybe I should explain what I want to accomplish :-)

    I created an Umbraco 7 Custom Section with a menu tree.

    When I rightclick a menu item I want to be able to add a new item.

    Therefor I need to pass the id of the parent node to my angularjs controller, so I know to which parent node I need to add the new node.

    Is this id available somewhere? (in $scope or $routeParams or somewhere else?)

    Or do I need to pass it myself using the example above?

    I can't find any documentation about this.

    Thank you for any help.

  • K.Garrein 164 posts 629 karma points
    Oct 07, 2015 @ 13:04
    K.Garrein
    1

    After a long search I found my additional data (named "parent" in my example) in the dialogOptions :-D

    var dialogOptions = $scope.dialogOptions;
    $scope.ProductCategoryPK = dialogOptions.currentAction.metaData.parent;
    

    Is that the correct way to retrieve it?

    Thanks. K.

  • David Armitage 505 posts 2073 karma points
    Apr 23, 2017 @ 07:21
    David Armitage
    0

    Hi,

    I am trying to do the exact same thing...

    Here is my menu item

    private void ContentTreeController_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
            {
                var item = new MenuItem("exportCsv", "Export to CSV");
                item.AdditionalData.Add("actionView", "/App_Plugins/exportCsv/index.html");
                item.AdditionalData.Add("parent", "1234");
                item.Icon = "save";
                e.Menu.Items.Insert(e.Menu.Items.Count, item);
            }
    

    Here is my html

    <div class="umbracoDialog umb-dialog">
        <p>Click <em>export</em> to download items to CSV</p>
    
        <script>
            var dialogOptions = $scope.dialogOptions;
            $scope.ProductCategoryPK = dialogOptions.currentAction.metaData.parent;
            alert(dialogOptions.currentAction.metaData.parent);
        </script>
    
        <div class="umb-dialog-footer btn-toolbar umb-btn-toolbar">
            <a href="/Umbraco/Backoffice/Api/NewsItemExport/Export?nodeTypeAlias=jobClassificationIndustry" target="_blank" class="btn btn-primary">
                Export
            </a>
        </div>
    </div>
    

    How do I access the $scope.dialogOptions; as in your example. Is this through javascript or am I understanding something wrong?

    Any assistance would be appreciated

  • K.Garrein 164 posts 629 karma points
    Apr 24, 2018 @ 10:04
    K.Garrein
    0

    I was working in javascript, indeed.

Please Sign in or register to post replies

Write your reply to:

Draft