如何检测在飞镖类中点击聚合物按钮

时间:2015-10-29 12:10:11

标签: dart polymer dart-polymer

我希望能够抓住纸张按钮上的点击事件并更改“clic me”文本。

MY-module.html:

<dom-module id="my-module">
 <template>
  <paper-button>{{btnTxt}}</paper-button>
 </template>
 <script type="application/dart" src="my-module.dart"></script>
</dom-module>

MY-module.dart:

@HtmlImport('my-module.html')
library blink.my_module;

import 'package:polymer/polymer.dart';
import 'package:web_components/web_components.dart' show HtmlImport;

@PolymerRegister('my-module')
class MyModule extends PolymerElement {

  @property String btnTxt = "Clic me!";

  MyModule.created() : super.created();
}

1 个答案:

答案 0 :(得分:1)

好的,要这样做,您必须将其添加到以下文件中:

MY-module.html:

//Adding the 'on-tap' tag with the dart methode name attribute, can also use 'on-click'
<paper-button on-tap="btnClicked">{{btnTxt}}</paper-button>

MY-module.dart:

@PolymerRegister('my-module')
class MyModule extends PolymerElement {

  @property String btnTxt = "Clic me!";

  MyModule.created() : super.created();

  //this method will listen for the linked event in the html
  @reflectable
  void btnClicked(Event e, [_]) {
    set('btnTxt', btnTxt = 'Button Clicked!');
  }

}