Skip to content

Instantly share code, notes, and snippets.

@tejainece
Created April 12, 2014 14:41
Show Gist options
  • Select an option

  • Save tejainece/10539035 to your computer and use it in GitHub Desktop.

Select an option

Save tejainece/10539035 to your computer and use it in GitHub Desktop.
Polymer.dart: Programmatically add template bindings
class CountNotifier extends ChangeNotifier {
int _count = 0;
int get count => _count;
set count(int count) {
_count = notifyPropertyChange(#count, _count, count);
}
}
CountNotifier counter = new CountNotifier();
TemplateElement count_template = new TemplateElement();
count_template.attributes["bind"] = "";
count_template.content.appendHtml("You have clicked {{count}} times.");
templateBind(count_template)
..model = counter;
document.body.children.add(count_template);
document.body.onKeyPress.listen((KeyboardEvent event) {
if(event.keyCode == KeyCode.ENTER) {
counter.count++;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment