-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-data-binding.html
42 lines (42 loc) · 1.02 KB
/
simple-data-binding.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!doctype html>
<html>
<head>
<link href="../components/polymer/polymer.html" rel="import">
<script src="../components/platform-dev/platform.js"></script>
<script src="../polymer-labs/binding-explorer/binding-explorer.js"></script>
</head>
<body>
<polymer-element name="x-foo" attributes="value">
<template>
{{value}}
</template>
<script>
Polymer('x-foo', {
valueChanged: function(old) {
console.log('valueChanged', old, this.value);
}
});
</script>
</polymer-element>
<polymer-element name="x-bar" attributes="value" noscript>
<template>
<x-foo value="{{value}}"></x-foo>
<br>
<x-foo value="{{value}}"></x-foo>
</template>
</polymer-element>
<button onclick="toggle()">toggle</button>
<br>
<x-bar value="foo"></x-bar>
<script>
function toggle() {
var el = document.querySelector('x-bar');
if (el.value === 'foo') {
el.value = 'bar';
} else {
el.value = 'foo';
}
}
</script>
</body>
</html>