自动绑定飞镖不工作,失败与错误状态错误 [英] auto-binding-dart is not working, fails with Bad State Error

查看:114
本文介绍了自动绑定飞镖不工作,失败与错误状态错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行这个自动绑定dart的基本示例自动绑定飞镖源。但它失败了

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


突破异常:错误状态:模板必须在
之前清除新的bindingDelegate


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

我使用stagehand polymerapp模板。
index.html

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

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

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!');
}


推荐答案

请在另一个模板中使用< template is =auto-binding-dart>

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

自动绑定点的目的是在Polymer元素外部具有一个用于胡子绑定的上下文。您可以使用自动绑定功能而不是主应用不在中。

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.

最外面的<$ c $

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

这篇关于自动绑定飞镖不工作,失败与错误状态错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆