Copied to clipboard

Flag this post as spam?

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


  • Mark Slade 48 posts 109 karma points
    Nov 11, 2022 @ 17:39
    Mark Slade
    0

    Extending the backoffice - Angular

    Hi,

    A newbie question regarding Angular & the backoffice:

    I've created a custom section with a tree. When I click an item on the tree it loads the Url: /umbraco#/myCustomSection/myCustomSectionTree/edit/{id}

    All loads perfectly, html / angular controller, but in my angular controller, how do I get the {id} value so that I can call my API controller and get the correct data that I want to display?

    Thanks.

    Mark

  • Ben Stephenson 4 posts 116 karma points
    Nov 15, 2022 @ 08:34
    Ben Stephenson
    100

    Hi Mark,

    As part of the angular controller, you can add in $routeParams as a property that can be injected. That then has an id field which you can use to pass to the API endpoint/resource factory. An example for a custom section we have in our sites is:

    function tVTreeController($scope, $http, $routeParams, umbRequestHelper, tVTreeResources, tVResources) {
    var vm = this;
    vm.id = $routeParams.id;
    vm.search = '';
    
    
    function init() {
        tVTreeResources.getItem(vm.id).then(function (results) {
            if (results.folder !== null) {
                vm.view = 'folder';
                vm.folder = results.folder;
            } else {
                vm.view = 'video';
                vm.video = results.video;
            }
        });
    }
    
        init();
    }
    

    I have the if, as the tree is made up of 2 types of items.

    Hope this helps

    Kind Regards, Ben

Please Sign in or register to post replies

Write your reply to:

Draft