3

I have created a custom section in umbraco to manage some data in an SQL database.

I can edit items OK but when adding I need to refresh the page to see my new row in the custom tree on the left.

How can I cause a refresh of my custom tree using AngularJS? My tree is called "clients".

I have tried debugging the code and looking at the source to find the event but I can't seem to work out how to do it.

Is there a method I can call on the umbTreeDirective somehow? Or an event to subscribe to?

I am fairly new to AngularJS and am struggling a little.

Rob Stevenson-Leggett
  • 35,279
  • 21
  • 87
  • 141

1 Answers1

4

You're looking for the navigationService.

This line is example of a syncTree call:

navigationService.syncTree({ tree: 'clients', path: content.path, forceReload: false, activate: true });

Here's a contrived, spaghetti promised but full example:

angular.module("umbraco")
.directive('nowplaying', ['navigationService', 'contentResource', 'contentEditingHelper', function (navigationService, contentResource, contentEditingHelper) {

                //spaghetti example to create new document
                contentResource.getScaffold(parentId, alias)
                .then(function (scaffold) {
                    var myDoc = scaffold;
                    myDoc.name = name;

                    //we have minimum to publish
                    contentResource.publish(myDoc, true, [''])
                        .then(function (content) { 
                            $scope.newlyCreatedNode = content;  

                                //Sync ('refresh') the tree!
                                navigationService.syncTree({ tree: 'clients', path: content.path, forceReload: false, activate: true });

                    });
                });
}]);

All of the Belle documentation lives here. -I'm not sure it's actively maintained, i can say for certain that one or two signatures have changed since it was first posted. That aside, it's the best resource i know of to interact with all the umbraco exposed modules and services.

pc-pdx
  • 502
  • 2
  • 9