How to know when the DOM is ready in Dart?

I want to get some information about some DOM elements after the page is ready, but I did not understand how to say it. I tried using document.on.contentLoaded and document.on.readyStateChange , but none of them work. In the following code, onContentLoaded() and onReadyChanged() will never be called.

 class WhiteTrace { WhiteTrace() { } void onContentLoaded(Event e) { print("onContentLoaded"); // This never gets called } void onReady() { print("onReady"); // Do stuff } void onReadyChanged(Event e) { print("onReadyStateChanged"); // This never gets called if (document.readyState == "complete") { onReady(); document.on.readyStateChange.remove(onReadyChanged); } } void onResize(Event e) { // Do stuff } void run() { write("Hello World!"); document.on.contentLoaded.add(onContentLoaded); window.on.resize.add(onResize); document.on.readyStateChange.add(onReadyChanged); print("readyState: " + document.readyState); if (document.readyState == "complete") { document.on.readyStateChange.remove(onReadyChanged); onReady(); } } void write(String message) { // the HTML library defines a global "document" variable document.query('#status').innerHTML = message; } } void main() { new WhiteTrace().run(); } 
+4
source share
1 answer

You do not need to worry about whether the DOM boots - the bulk of the Darts only starts when the DOM is fully loaded.

http://www.dartlang.org/articles/embedding-in-html/

"Dart code only runs after parsing the page. Dart programmers may assume that the DOM is fully loaded."

+7
source

Source: https://habr.com/ru/post/1385398/


All Articles