Binding.scala
Binding.scala copied to clipboard
Example code in README.md doesn't work
Hey there,
I've had some trouble running the example code in README.md. More specifically, this code didn't work for me in Firefox 58:
@JSExport
def main(): Unit = {
dom.render(document.body, table)
}
When I tried this, I found that it crashes, because document.body is null at that point. So I tried running the code in an event handler instead.
def main(): Unit = {
window.addEventListener("load", { (_: Event) =>
dom.render(document.body, table)
})
}
And lo and behold, it worked!
Hi @mberndt123 , did you put SampleMain().main() inside of the <body>, as described in https://github.com/ThoughtWorksInc/Binding.scala#step-5-invoke-the-main-method-in-a-html-page ?
Hi Atry,
Thanks for the response! I used scalaJSUseMainModuleInitializer := true, so I'm not invoking main manually at all, and I did put the <script> element into the <head> since I thought that's where they generally belong… Perhaps it's a good idea to add a hint about this particular pitfall, I might not be the only one to fall into it.