Created
July 4, 2017 18:25
-
-
Save matanlurey/e69f44e94126048a37a50039e9576c2c to your computer and use it in GitHub Desktop.
An example of using dart:html
This file contains 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
<html> | |
<body> | |
<div id="todo-list"></div> | |
</body> | |
<script type="application/dart" src="main.dart"></script> | |
<script src="packages/browser/dart.js"></script> | |
</html> |
This file contains 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
import 'dart:html'; | |
main() { | |
final sundays = const [ | |
'sleep in', | |
'eat brunch', | |
'wash car', | |
]; | |
document.querySelector('#todo-list') | |
..append(new UListElement() | |
..children.addAll( | |
sundays.map(_createListItem), | |
)); | |
} | |
Element _createListItem(String item) { | |
final li = new LIElement(); | |
final button = new ButtonElement() | |
..text = 'Done' | |
..onClick.listen((_) => li.remove()); | |
li | |
..appendText(item) | |
..append(button); | |
return li; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment