2014-10-28 53 views
0

我想在独立文件中创建模板库。如何在聚合物中导入模板?

./my-components/templates.html

<template id="overTemplate"> 
    <div on-mouseover="{{mouseOverHandler}}">OVER</div> 
</template> 
..... 

在我的高分子元素连接此文件:

<link rel="import" href="./my-components/templates.html"> 

然后用这个模板:

<template bind ref="overTemplate"></template> 

如何去做吧?

回答

0

怎么样?

var link = document.querySelector('link[rel=import]'); 
var content = link.import.querySelector('#overTemplate'); 
document.body.appendChild(document.importNode(content, true)); 

现金先生“聚合物”多德森... http://robdodson.me/blog/2013/08/20/exploring-html-imports/

聚合物具有所谓的进口,但据我可以告诉它准备只导入聚合物元素帮手。

1

以上不适用于Polymer 1.0,因为基于DOM修改,模板注释绑定不再是动态的。 There is a tag,目前是一个停止差距,直到聚合物团队提供该能力,即尝试提供参考模板。