Copied to clipboard

Flag this post as spam?

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


  • Steve Morgan 1348 posts 4457 karma points c-trib
    Aug 02, 2016 @ 09:54
    Steve Morgan
    0

    Knowing when the Umbraco Backoffice has finished creating all properties and loaded data

    Hi,

    Is there anyway from an angular controller to know when all the divs and content have been loaded in the back office?

    I have a custom property editor that's being used in an Archetype data type and the controller fires before the Archetype instance has been created it seems (as the divs I try and target don't exist when the controller fires)... how can I know Umbraco / Archetype has finished loading before running custom code - is there an event that's fired?

    At the moment I have used a stinky setTimeout but this is destined to fail.

    Kind regards

    Steve

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Aug 03, 2016 @ 09:37
    Steve Morgan
    1

    I've solved this... credit to http://blog.brunoscopelliti.com/run-a-directive-after-the-dom-has-finished-rendering/

    Use the angular $timeout functionality - but without a delay (set it to zero).. this adds it to the "queue" and will only fire when Archetype et al have finished creating the new instance.

    You need to pass $timeout to your Controller:

    angular.module("umbraco")
        .controller("My.FileUploadProgress",
         function ($scope, $timeout) {
    

    Then just call your function via a timeout (note how a var is used and a function - otherwise the params are passed immediately not at timeout):

    previewTimeout = $timeout(function () { SetPreviewImage($scope.model.value, $("#" + $scope.model.alias + "-parent")); }, 0);
    

    or wrap your controller code in one:

     angular.module("umbraco").controller("My.FileUploadProgress",
        function ($scope, $timeout) {
         initTimeout = $timeout(function () {
             assetsService
            .load([
                 [[... your js...]]
            ])
            .then(function () {
    
                 [[... your custom controller code]]]
    
                });
            });
    
         }, 0);
     });
    

    Hope this helps someone in the future!

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft