Created
April 12, 2014 13:59
-
-
Save tejainece/10537085 to your computer and use it in GitHub Desktop.
Polymer.dart bindings without custom element. In this example, we will only bind using binding delegates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CountNotifier extends ChangeNotifier { | |
| int _count = 0; | |
| int get count => _count; | |
| set count(int count) { | |
| _count = notifyPropertyChange(#count, _count, count); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CountNotifier counter = new CountNotifier(); | |
| Map globals = { | |
| "count": counter, | |
| }; | |
| templateBind(querySelector('#counter')) | |
| ..bindingDelegate = new PolymerExpressions(globals: globals); | |
| querySelector("#inc_count").onClick.listen((_) { | |
| counter.count++; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template id="counter" bind> | |
| You have clicked {{count.count}} times. | |
| </template> | |
| <input type="button" id="inc_count" value="Count"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment