简体   繁体   English

如何在聚合物中导入模板?

[英]How to import template in polymer?

I want create template libraray in isolated file. 我想在隔离文件中创建模板libraray。

./my-components/templates.html ./my-components/templates.html

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

And connect this file in my polymer-element: 并将此文件连接到我的聚合物元素中:

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

Then use this template: 然后使用此模板:

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

How to do it? 怎么做?

The above does not work with Polymer 1.0 as template annotation bindings are no longer dynamic based on DOM modifications. 以上内容不适用于Polymer 1.0,因为模板注释绑定不再基于DOM修改而动态。 There is a tag , currently a stop gap until the Polymer team provides that ability, that attempts to provide reference templates. 有一个标签 ,当前是一个停止的间隙,直到Polymer团队提供该功能为止,该标签试图提供参考模板。

How about? 怎么样?

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

Credits to Mr 'Polymer' Dodson... http://robdodson.me/blog/2013/08/20/exploring-html-imports/ 感谢'Polymer'Dodson先生... http://robdodson.me/blog/2013/08/20/exploring-html-imports/

Polymer has a helper called import but as far as I can tell it is ready to import polymer-elements only. Polymer有一个名为import的助手,但据我所知,它仅准备导入聚合物元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM