Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bind a method to a custom attribute declaratively

  • Loading branch information...
commit 39567d11bb09935d43445e2f38539f87d6df5c05 1 parent 078dad5
@zoechigist zoechigist authored
View
13 web/custom_element_with_custom_attribute_binding/index.dart
@@ -4,6 +4,19 @@ import 'package:polymer/polymer.dart';
class Model extends Object with ObservableMixin {
@observable
String value = "Initial value";
+
+ // bind an event method to a custom attribute
+ var myBlur;
+
+ Model() {
+ myBlur = onBlur;
+ }
+
+ void onBlur(e) {
+ // this prints the wrong value because value is not updated
+ // see comment in index.html
+ window.alert(value);
+ }
}
main() {
View
2  web/custom_element_with_custom_attribute_binding/index.html
@@ -9,7 +9,7 @@
<body>
<template id="tmpl" bind>
- <my-element value="{{value}}"></my-element>
+ <my-element value="{{value}}" myblur="{{myBlur}}"></my-element>
<!-- This should be updating, but it's not updating -->
<!-- See http://code.google.com/p/dart/issues/detail?id=12440 -->
View
8 web/custom_element_with_custom_attribute_binding/my_element.dart
@@ -3,4 +3,12 @@ import 'package:polymer/polymer.dart';
@CustomTag('my-element')
class MyElement extends PolymerElement with ObservableMixin {
@observable String value;
+
+ // bind an event method to a custom attribute
+ var myblur;
+
+ inserted(){
+ super.inserted();
+ this.onBlur.listen((e) => myblur(e));
+ }
}
View
2  web/custom_element_with_custom_attribute_binding/my_element.html
@@ -1,6 +1,6 @@
<!DOCTYPE html>
-<polymer-element name="my-element" attributes="value">
+<polymer-element name="my-element" attributes="value myblur">
<template>
<input value="{{value}}">
<p>The element's value is {{value}}</p>
Please sign in to comment.
Something went wrong with that request. Please try again.