-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-binding.html
92 lines (78 loc) · 3.14 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../iron-input/iron-input.html">
<dom-module id="data-binding">
<script>
/**
* `data-binding`
* Test examples
*
* @customElement
* @polymer
* @demo demo/data-binding.html
*/
class FireEvent extends Polymer.Element {
static get is() { return 'data-binding'; }
static get properties() {
return {
nativeValue: String,
ironValue: String,
selectValue: {
type: String,
value: 'Option1',
},
valueEvent: String,
valueEvent2: String,
};
}
static get template() {
return Polymer.html`
<style>
:host {
display: block;
}
input, iron-input, select {
display: block;
margin-bottom: 10px;
}
</style>
<label for="nativeInput">Type something</label>
<input id="nativeInput" type="text" value="{{nativeValue::input}}">
<label for="nativeInputInsideIronInput">Type more things</label>
<iron-input bind-value="{{ironValue}}">
<input id="nativeInputInsideIronInput" type="text" value="{{value1::input}}">
</iron-input>
<label for="mySelect">Select one option</label>
<select id="mySelect" value="{{selectValue::change}}">
<option value="Option1">Option 1</option>
<option value="Option2">Option 2</option>
<option value="Option3">Option 3</option>
<option value="Option4">Option 4</option>
</select>
<label for="myInputWithEventHandling">Input with event 1</label>
<input id="myInputWithEventHandling" on-input="_onInput">
<label for="myInputWithEventHandling2">Input with event 2</label>
<input id="myInputWithEventHandling2">
<button on-click="_showResultInConsole">Check the result in console</button>
`;
}
connectedCallback() {
super.connectedCallback();
this.shadowRoot.querySelector('#myInputWithEventHandling2').addEventListener('input', this._onInput2.bind(this));
}
disconnectedCallback() {
super.disconnectedCallback();
this.shadowRoot.querySelector('#myInputWithEventHandling2').removeEventListener('input', this._onInput2.bind(this));
}
_onInput(event) {
this.set('valueEvent', event.currentTarget.value);
}
_onInput2(event) {
this.set('valueEvent2', event.currentTarget.value);
}
_showResultInConsole() {
console.log(this.nativeValue, this.ironValue, this.selectValue, this.valueEvent, this.valueEvent2);
}
}
window.customElements.define(FireEvent.is, FireEvent);
</script>
</dom-module>