Copied to clipboard

Flag this post as spam?

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


  • Ian Naylor 6 posts 57 karma points
    Jul 01, 2015 @ 07:33
    Ian Naylor
    0

    Umbraco angular service for getPropertyValue

    Hi,

    I have added a custom Context Menu item and when this is clicked I need to get a property value from the current Content Node.

    I have been able to do this using the below code, but it seems overly convoluted.

    {     
    

    contentResource.getById(appState.getMenuState('currentNode').id).then(function (content) { var tabs = content.tabs;

        for (var x = 0; x < tabs.length; x++) 
        {
    
            var tab = tabs[x];
    
            if (tab.alias === "property tab alias") 
        {
    
                for (var y = 0; y < tab.properties.length; y++) 
            {
    
                    var property = tab.properties[y];
    
                    if (property.alias === "property alias") 
                {
    
                        $scope.Value= property.value;
    
                        y = tab.properties;
    
                        x = tabs.length;      
    
                            }
                    }
            }
    }
    

    }); }

    Does anyone know of a method in the Umbraco angular services or resources that would do the same thing?

  • Casper Andersen 126 posts 508 karma points
    Sep 01, 2015 @ 11:47
    Casper Andersen
    0

    i think that is the most efficient way of doing it, and that also takes care if anyone should move around any tabs or properties, but if you know where they are located and that no one is going to move them. You can instead of for looping them you can do properties[0] and specify the exact place in the array you want to access alhough i would not recommend this

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Sep 01, 2015 @ 11:53
    Warren Buckley
    0

    I would agree with Casper that if the property gets moved around to continue using your loop.

    However as with most things there are 101 different approaches, another approach may be to create your own C# WebAPI endpoint when you do a HTTP GET & pass your NodeID to get exactly the data you want/need.

    Obviously this requires some knowledge of C# but sometimes I find it easier to create my own endpoints to get the data in the format I want rather than writing a fair bit of JS to massage & manipulate the data into the way I want it.

    I hope this gives you a different perspective on this.

    Cheers,
    Warren :)

  • Casper Andersen 126 posts 508 karma points
    Sep 01, 2015 @ 11:58
    Casper Andersen
    0

    I agree with warren sometimes you just have to talor things to the specifications you require, but i would like to point out, that any content you want to pull, be it a member or some other content, they are built the exact same way, with tabs and properties that have aliases, so perhaps you should create yourself a nice function, that does all your login and when u want some content you can use your function and pass in your tab alias and you property alias and hey presto you have content.

Please Sign in or register to post replies

Write your reply to:

Draft