更好的辦法我有以下元素:通過綁定到子元素聚合物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