如何在聚合物中导入模板? [英] How to import template in polymer?
本文介绍了如何在聚合物中导入模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在隔离文件中创建模板libraray.
I want create template libraray in isolated file.
./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">
然后使用此模板:
<template bind ref="overTemplate"></template>
该怎么做?
推荐答案
怎么样?
var link = document.querySelector('link[rel=import]');
var content = link.import.querySelector('#overTemplate');
document.body.appendChild(document.importNode(content, true));
"Polymer" Dodson先生的信用... http://robdodson.me/blog/2013/08/20/Exploration-html-imports/
Credits to Mr 'Polymer' Dodson... http://robdodson.me/blog/2013/08/20/exploring-html-imports/
Polymer有一个名为import的助手,但据我所知,它仅准备导入聚合物元素.
Polymer has a helper called import but as far as I can tell it is ready to import polymer-elements only.
这篇关于如何在聚合物中导入模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文