Kunal Deo
Kunal Deo

Reputation: 2298

auto-binding-dart is not working, fails with Bad State Error

I am trying to run this basic example of auto-binding-dart auto binding dart source. But it fails with

Breaking on exception: Bad state: Template must be cleared before a new bindingDelegate can be assigned

I am doing this using stagehand polymerapp template. index.html

<html>
<head>
  <link rel="import" href="../lib/main_app.html">
  <link rel="stylesheet" href="styles.css">
   <script type="application/dart">export 'package:polymer/init.dart';</script>
</head>

<body unresolved>
  <main-app></main-app>
</body>
</html>

main_app.html

<link rel="import" href="../../packages/polymer/polymer.html">
<polymer-element name="main-app">
  <template id="my-template" is="auto-binding-dart">
    <style>
      :host {
        display: block;
      }
    </style>
      <div>Say something: <input value="{{value}}"></div>
      <div>You said: {{value}}</div>
      <button on-tap="{{buttonTap}}">Tap me!</button>
  </template>
  <script type="application/dart" src="main_app.dart"></script>
</polymer-element>

main_app.dart

import 'dart:html';
import 'package:polymer/polymer.dart';
@CustomTag('main-app')
class MainApp extends PolymerElement {
  /// Constructor used to create instance of MainApp.
  MainApp.created() : super.created();
  ready(){
    super.ready();
    var template = document.querySelector('#my-template');
    template.model = new MyModel(); 
  }  
}
class MyModel {
  String value = 'something';
  buttonTap() => window.console.info('tap!');
}

Upvotes: 1

Views: 259

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657308

You don't need to use the <template is="auto-binding-dart"> inside another template.

The point of auto-binding-dart is to have a context for mustache binding outside a Polymer element. You could use auto-binding-dart instead of your main-app not inside.

I prefer an app-element (or main-app like you named) over auto-binding-dart because you don't need a main method this way.

The outermost <template> tag inside your <polymer-element ...> uses the elements class automatically as model (binding context).

Upvotes: 1

Related Questions