Copied to clipboard

Flag this post as spam?

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


  • iNETZO 93 posts 412 karma points
    28 days ago
    iNETZO
    0

    Hi,

    Sometimes we're making Content Apps that load data from other sources. We do this in the constructor of the angular controller. The problem is that the controller is initalised even if the Content App is not used. So it takes time to load the Content App when opening the document node even if the Content App is not clicked.

    Is there a way to make this event-driven? So that an event is invoked when the Content App is selected? We now do it like this but it is not very elegant:

    $('button.umb-sub-views-nav-item__action').on('click', function (e) {
        var apps = editorState.current.variants[0].apps;
        $.each(apps, function (appid) {
            if (apps[appid].alias == "OurAppAlias") {
                vm.versionIsActive = apps[appid].active;
            };
        });
    
        if (vm.versionIsActive) {
            onInit()
        }
    
    });
    

    Is there a better way to do this?

    iNETZO

  • Kevin Jump 1777 posts 11418 karma points MVP 4x c-trib
    28 days ago
    Kevin Jump
    100

    Hi,

    yes, just had to do this yesterday!

    you can listen for the app.tabChange event, which is triggered when the user swiches between content apps.

    so you can do a similar thing you what you have, but only run when your 'tab' is active.

    e.g i have this (where vm.initialized is my variable to make sure we only do it once)

    eventsService.on("app.tabChange", function (event, args) {
       $timeout(function () {
           if (args.alias === 'myContentApp' && !vm.initialized) {
               onInit();
               vm.initialized = true;
             }
          }
       });
    });
    
  • iNETZO 93 posts 412 karma points
    28 days ago
    iNETZO
    0

    Hi Kevin,

    Thank you very much for sharing your solution! This is indeed much cleaner way.

    Best regards,

    iNETZO

Please Sign in or register to post replies

Write your reply to:

Draft