Skip to content

Instantly share code, notes, and snippets.

@arthurevans
Created October 3, 2014 16:44
Show Gist options
  • Save arthurevans/3fa25f7f9a395c6db731 to your computer and use it in GitHub Desktop.
Save arthurevans/3fa25f7f9a395c6db731 to your computer and use it in GitHub Desktop.
Dynamic import
<link rel="import" href="components/polymer/polymer.html">
<polymer-element name="dynamic-element" attributes="description">
<template>
<style>
:host {
display: block;
}
</style>
<p>I'm {{description}}, now!</p>
</template>
<script>
Polymer({
description: 'a custom element'
});
</script>
</polymer-element>
<html>
<head>
<script src="components/platform/platform.js"></script>
<link rel="import" href="components/polymer/polymer.html">
</head>
<body>
<dynamic-element>
I'm just an unknown element.
</dynamic-element>
<button>Import</button>
<script>
var button = document.querySelector('button');
button.addEventListener('click', function() {
Polymer.import(['dynamic-element.html'], function() {
document.querySelector('dynamic-element').description = 'a dynamic import';
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment