2014-09-19 94 views
0

我新的聚合物,並希望結合上手簡單的東西。我對所有的術語都不太熟悉,所以我很難對谷歌進行正確的評估。簡單的節點與聚合物

無論如何,我發現我可以在「淺DOM」中訪問文本的textContent?相當容易:

<!-- This is part of my-element element --> 
<template> 
    {{textContent}} <!-- Outputs all the text --> 
    {{foo.textContent}} <!-- Doesn't output anything as I'd hoped it would.. --> 
    {{test.textContent}} <!-- Doesn't output anything as I'd hoped it would.. --> 
</template> 

不過,我似乎無法到我的主網頁中訪問子元素的具體文本內容:

<!-- This is part of index.html --> 
<my-element> 
    <test>Some text here</test> 
    <foo>Something else</foo> 
</my-element> 

那麼,有沒有在的的textContent並明確得到的一種方式?我知道這對JS來說可能相當簡單,但我有一種感覺,這可能是一種內置的聚合方式,就像訪問{{textContent}}一樣。

回答

1

好了,這是相當簡單的。而不是使用鬍子語法我可以做我的模板如下:

Foo is: <content select="foo"></content><br> 
Test is: <content select="test"></content><br> 

此輸出:

Foo is Some text here 
Test is: Something else