Search code examples
dartdart-polymerpolymer

Programmatic custom element broken in dart polymer 0.9.5?


The earlier solution for programmatic custom element creation in polymer 0.8.5 seems to be broken in polymer 0.9.5.

If we modify the standard click-counter example to use programmatic element creation, like so:

main() {
  Logger.root.level = Level.ALL;
  Logger.root.onRecord.listen((LogRecord rec) {   
    print('${rec.loggerName}: ${rec.level.name}: ${rec.time}: ${rec.message}');
  });

  initPolymer();

  var clickCounter = new Element.tag('click-counter');     
  document.body.children.add(clickCounter);
}

the on-click events are correctly invoking the {{increment}} method, but the {{count}} value is not updated in the HTML.


Solution

  • Polymer code should be run from

    import "package:polymer/polymer.dart";
    
    main() {
      initPolymer().run(() {
        // code here works most of the time
        Polymer.onReady.then((value) {     
          // some things must wait until onReady callback is called
          // for an example look at the discussion linked below
        });
      });
    }
    

    simple tooltip working in dartium, not as javascript