I was fiddling with the "new" instructions for polymer dart 0.10.0-pre.10 only to realize I had package 0.9.5
installed (on an updated Dart Editor). And could only get code to run using main() => dostuff();
Adding component1 as per instructions just broke whatever worked.
I set pubspec.yaml
polymer dependency to >= 0.9.9
and it auto pub gets the version 0.10.0-pre.10
. Then I made changes as suggested and moved dostuff()
to a custom element class (extends PolymerElement
) and put @initMethod
above it. It does not run.
And as I got it to run before I was unable to find a way to bind new items from a JSON file (which I successfuly got through http) to the polymer element.
mylist.dart
import 'package:polymer/polymer.dart';
import 'dart:html';
@CustomTag('my-list')
class MyListElement extends PolymerElement {
@observable List mylist = ['one', 'two', 'three'];
@initMethod
static dostuff() {
print("initMethod");
// get json and pass to mylist
}
}
mylist.html
<polymer-element name="my-list">
<template>
<ul>
<template repeat="{{item in mylist}}">
<li>{{item}}</li>
</template>
</ul>
</template>
<script type="application/dart;component=1" src="mylist.dart"></script>
</polymer-element>
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample app</title>
<link rel="import" href="packages/polymer/polymer.html">
<link rel="import" href="mylist.html">
<script src="packages/browser/dart.js"></script>
</head>
<body>
<h1>MyList</h1>
<div id="container1">
<json-list id="my-list1"></json-list>
</div>
</body>
</html>