Copied to clipboard

Flag this post as spam?

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


  • Andy 9 posts 30 karma points
    Feb 03, 2017 @ 02:51
    Andy
    0

    Hey,

    I am creating a property editor for a 'share page' feature. Just a bunch of social media website icons that can be clicked on, by an editor, and selected. The resulting pages will the have appropriate 'share' button(s).

    The list of social media sites to choose from is pulled from a static JSON file, and the HTML has generated ID's based on this JSON. I find that, using Angular, I need to use the $timeout service in order to address these ID's in the controller function. But I feel I may be using the wrong approach entirely. In a nutshell:

      $timeout(function () {   
           // do my thing here, set selected state CSS style on the buttons.
    
        }, 500  // we wait briefly because the dynamic id's might not yet be known to Angular
        );
    

    My question is this, what the heck am I missing here? Its a problem as it feels messy, but also because it produces a brief flicker as the selected state changes after the 500ms. Does Umbraco provide any Angular services for solving this issue, or is there a fundamentally better way?

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Feb 03, 2017 @ 07:30
    David Brendel
    0

    Hi Andy,

    sometimes the problem is that the html part is not rendered as the angular stuff is processed. I got this problem and the only way to get past this was to use the timeout function. But I don't think that you have to provide a time at all.

    When you use it without time the stuff in the method will be done in the next digest cycle which should appear after the html is rendered.

    At least that's what I read when I had the problem.

    How do you load your json file?

    Regards David

  • Andy 9 posts 30 karma points
    Feb 03, 2017 @ 10:31
    Andy
    0

    Thanks David. Yes, I understand the problem as I'm confident with Angular, but was wondering if there was some some sort of recommended tactic of use in these property editor scenarios.

    I did try the no args option with $timeout, but it didn't seem to work unless I added a delay - Ill try again though; things got a bit un-systematic when the frustration kicked in!

    JSON loaded with the Umbraco asset manager Angular service, and tried addressing the id's in and out of the resolved promise.

    From what you say, seems like maybe this is the normal/accepted way (hopefully with a working no-args $timeout, I can make the flicker go away)

    Thanks, very much appreciated, will post how I go ASAP.

Please Sign in or register to post replies

Write your reply to:

Draft