Polymer querySelector works with DartVM, but not in Chrome after compilation

Has a weird problem. In my Dart code, I have some polymer components on the screen, and one of them has a method that I call from my main ().

I get a link to it by doing

PolyComp poly = querySelector("#idOfPolymer");
poly.flash();

This works great in darts. The page loads and PolyComp starts flashing. However, when I run this in Chrome by running the Build Polymer application from the Dart IDE, I get an error message that says it cannot call flash () on null.

I ended up firing it just using the event bus and letting PolyComp listen on my event, but this is overkill.

What am I doing wrong? This happens in the latest Chrome, Firefox, and Safari browsers.

Edit:

I built the following application for an IP application for JS and ran into the same problem. https://github.com/sethladd/dart-polymer-dart-examples/blob/master/web/todo_element/todo.html

Works on DartVM, not Chrome, because it calls a method on the null item.

+4
source share
1 answer

When you run this code from a method main(), it is probably a synchronization problem. You can try something like

import "package:polymer/polymer.dart";

main() {
  initPolymer().run(() {
    // code here works most of the time
    Polymer.onReady.then((e) {     
      // some things must wait until onReady callback is called
    });
  });
}

see also how to realize the main function in polymer applications

+7
source

All Articles