Skip to content

Instantly share code, notes, and snippets.

@robrez
Created August 18, 2016 18:17
Show Gist options
  • Save robrez/09b141ce55dea3baf1a6bf6b85be4ea9 to your computer and use it in GitHub Desktop.
Save robrez/09b141ce55dea3baf1a6bf6b85be4ea9 to your computer and use it in GitHub Desktop.
Dynamic template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Polymer Element Test Case</title>
<base href="//polygit.org/components/">
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="polymer/polymer.html">
<dom-module id="x-foo">
<template>
<button on-tap="_handleTap">tap</button>
<div id="content"></div>
</template>
<script>
Polymer({
is: 'x-foo',
properties: {
_count: {
type: Number,
value: 0
}
},
behaviors: [
Polymer.Templatizer
],
_handleTap: function() {
if (!this.ctor) {
var d = document.createElement("div");
d.innerHTML = "<div>test {{count}}</div>";
var t = document.createElement("template");
t.content.appendChild(d);
this.templatize(t);
console.log('templatizing it');
}
var n = this.stamp({count: ++this._count});
Polymer.dom(this.$.content).appendChild(n.root);
}
})
</script>
</dom-module>
</head>
<body>
<x-foo></x-foo>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment