1
votes

I have an element html-import that accepts an href and builds a new href to import.

<html-import href="some.html"></html-import>
<script>
    Polymer({
        is: "html-import",
        ready: function() {
            var href = "outside/config/" + this.href; 
            this.importHref(href)
        }
    })
</script>

The element is successfully importing elements but is not registering the elements with Polymer before the parent element's template is created. The below code shows me a console warning Could not find style data in module named red-css.

<html-import html-href="style/css.html"></html-import>
<dom-module>
    <template>
        <style include="red-css"></style>
    </template>
</dom-module>

Is there a way to ensure that I can import html dynamically before the parent template is created?

2

2 Answers

0
votes

Have you tried using 'created' callback, instead of 'ready'?

https://www.polymer-project.org/1.0/docs/devguide/registering-elements

0
votes

Honestly, I'm not sure what your use-case is. Without more details, I can't see what the objective for <html-import> element is?

However, I'm guessing that you're looking for a way to load style modules imperatively, which can then be utilised by elements via the <style include="xxx"> mechanism.

Unfortunately, that is not supported today (Polymer 1.5.0) - Polymer shims the include="xxx" at creation time, so that happens even before Polymer processes your template (where the import codes lie).

Have a look at this GH issue for reference: https://github.com/Polymer/polymer/issues/3123