I want to access the value of a paper-input over two levels. Unfortunately this is not working. Here is my minimum example:
<html>
<head>
<base href="https://polygit.org/polymer+:master/webcomponents+:master/shadycss+webcomponents+:master/components/">
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="paper-input/paper-input.html">
</head>
<body>
<dom-module id="text-block">
<template>
<style>
#input-test {
width: 100%;
}
</style>
<paper-input id="input-test" label="Test" value="{{blockValue}}"></paper-input>
</template>
<script>
class TextBlock extends Polymer.Element {
static get is() {
return 'text-block';
}
static get properties() {
return {
blockValue: {
type: String,
value: '',
observer: '_onBlockValueChanged'
}
}
}
_onBlockValueChanged() {
console.log('Block value changed');
console.log(this.blockValue);
}
}
customElements.define(TextBlock.is, TextBlock);
</script>
</dom-module>
<dom-module id="my-element">
<template>
<text-block block-value="{{_myValue}}"></text-block>
</template>
<script>
HTMLImports.whenReady(function() {
class MyElement extends Polymer.Element {
static get is() { return 'my-element'; }
static get properties() {
return {
_myValue: {
type: String,
value: '',
observer: '_myValueChanged'
}
};
}
_myValueChanged() {
console.log('_myValue changed');
console.log(this._myValue);
}
}
customElements.define(MyElement.is, MyElement);
});
</script>
</dom-module>
<my-element></my-element>
</body>
</html>
When I change the content of the paper-input, the change is forwarded to the blockValue of the text-block element, but not further to _myValue of the main element. It seems the binding with
block-value={{_myValue}}
is not sufficient. What else do I need to do?
You need to declare the blockValue
in your text-block
element with notify: true
otherwise the parent element won't be notified about changes:
blockValue: {
type: String,
value: '',
notify: true,
observer: '_onBlockValueChanged'
}