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?
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.
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.
Angular and Data Types
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:
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?
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
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.
is working on a reply...