更好的办法我有以下元素:通过绑定到子元素聚合物1.0
<link rel="import" href="../my-control/my-control.html" />
<dom-module id="my-page">
<template>
<!-- pass the value down to the children element -->
<my-control my-property="{{myProperty}}"></my-control>
</template>
<script>
Polymer({
is: 'my-page',
properties: {
myProperty: {
type: String,
value: '',
reflectToAttribute: true
}
}
});
</script>
</dom-module>
这是“孩子”控制
<dom-module id="my-control">
<template>
<!-- print the value of the property -->
<span>{{myProperty}}></span>
</template>
<script>
Polymer({
is: 'my-control',
properties: {
myProperty: {
type: String,
value: '',
reflectToAttribute: true
}
}
});
</script>
</dom-module>
这是我如何使用它。我这样做是因为实际上"my-page"
并不真的需要一个属性,但是"my-control"
可以,它包含在"my-page"
的DOM中。有没有其他办法可以做到这一点?因为我传递了一个模型,而且我必须按属性为每个属性反序列化它?
<link rel="import" href="/my-page/my-page.html" />
<!-- declare parent element and value -->
<my-page my-property="ABCDE-12345"></my-page>
不是。我能想到的唯一方法是在js select'my-page'访问它的'shadow dom'(方法在V0和V1规范中有所不同),然后选择'my-control'并赋值。 – a1626
我希望像Angular这样的“父”数据绑定语法有,但我加倍检查,我没有找到任何有关聚合物1.x文档 – Raffaeu
聚合物 – a1626