Newbie here. I have a Javascript/CSS clock that I wrote that works great. It takes an injected message every one second to update the time. All is good but of course there is a delay of up to one second when you open that tab, during which the hands sit as 12 noon as the clock is waiting for the next message. It's a minor thing but it does not look very polished.
Is there a way to somehow stimulate the message injection on opening the tab?
I read some threads on the ui control node and the help for the node but I'm afraid I don't know how to apply it, or if this is what is needed anyway.
Would it not be easier if the ui-template node did its own updating every second, of the time, as the code is run in the browser, not node-red injecting a message every second and sending it to the browser.
Have look at setTimeout and setInterval JS clock.
Yes, of course,. Quite a lot. I did not post as I thought it not pertinent, is it? The Angular just gets a message acting purely as a trigger and sets the position of clock hands based on the current time from Date(), as can be seen. And of course there is HTML to make the page.
That's a standard bit of Angular straight from the Help for the ui template node.
I am a Node RED beginner so I'sm sure the answer is something simple, as you have suggested, but I don't know how to implement it in the context of Node RED.
I believe I have figured it out. Instead of using the Angular scope I simply changed to using a plain Javascript function and used setInterval() as suggested and it works. I did not realise that it was not essential to use the Angular scope watcher. Hopefully this may help other beginners in the future.
Adding a call to the function that sets the clock hands at the top makes the refresh instant, and then setInterval(0 takes over.
Cool, you managed to work it out, glad to of helped.
p.s. I asked for css as i like to test before posting if possible, and I am sure others might like the full picture or a link to it.
Actually I'm not done yet. When I move away from that tab the console continously prints dozens of messages:
Uncaught TypeError: Cannot read properties of null (reading 'style') at myClock (<anonymous>:8:38)
So now the problem has shifted. Not sure what to do about that! Especially since I removed the initial single call to myClock(). Worse, this happens when I revert to the orginal Angular scope watch code.