Copied to clipboard

Flag this post as spam?

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


  • iNETZO 134 posts 497 karma points c-trib
    Sep 24, 2020 @ 07:30
    iNETZO
    1

    Content App events?

    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 2343 posts 14890 karma points MVP 8x c-trib
    Sep 24, 2020 @ 08:08
    Kevin Jump
    101

    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 134 posts 497 karma points c-trib
    Sep 24, 2020 @ 16:22
    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