How can I pass attribute to an imported hidden custom polymer element

Yohann Streibel

Before I created my custom Polymer element :

<polymer-element name="my-custom-element" attributes="key" hidden>
  <script>
    Polymer({});
  </script>
</polymer-element>

I would like to pass an attribute to my imported hidden custom Polymer element when I import it on an other custom Polymer element like this :

<link rel="import" href="../my-custom-element/my-custom-element.html" key="15">

How could I do ? It is possible to do this ? If not what is the good way ?

robdodson

As wirlez pointed out, you'll want to import your element's definition, create an instance, and set the key value as an attribute.

For example:

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8 />
    <title>Polymer</title>
    <script src="http://www.polymer-project.org/components/webcomponentsjs/webcomponents.js"></script>
    <!-- import element definition from jsbin -->
    <link rel="import" href="http://jsbin.com/mojadu.html">
  </head>
  <body>
    <x-foo key="42"></x-foo>
  </body>
</html>

element definition

<!-- Make sure your element imports Polymer as a dependency -->
<link rel="import" href="http://www.polymer-project.org/components/polymer/polymer.html">

<polymer-element name="x-foo" attributes="key" hidden>
  <template>
    <h1>Hello from x-foo</h1>
    <h2>The key is {{key}}</h2>
  </template>
  <script>
    Polymer({
      keyChanged: function(oldVal, newVal) {
        console.log('the key is', newVal);
      }
    });
  </script>
</polymer-element>

Here's the example running in jsbin.

If you look in the console, you'll see the element is logging the value for key.

If you're trying to access the element using JavaScript in index.html you may need to wait for the polymer-ready event before manipulating it.

ex:

document.addEventListener('polymer-ready', function() {
  var el = document.querySelector('x-foo');
  // do something with x-foo that involves its key
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can i make custom Polymer element hidden?

From Dev

How can i make custom Polymer element hidden?

From Dev

How can I pass a Polymer Object beetwen 2 custom elements

From Dev

How to Bind Attribute from Custom Polymer Element to angularjs

From Dev

How can I trigger an event on an element in Polymer?

From Dev

How can I pass a wct test while rearranging children spans in a Polymer element?

From Dev

How to pass data from JavaScript code to Polymer custom element?

From Dev

DART POLYMER: How I can update a property from a custom element by another?

From Dev

Polymer 1: How can I set up paper-checkbox label dynamically using a custom element

From Dev

How can I handle paper-dropdown-close event in my custom polymer element

From Dev

How to update hidden$= attribute in a Polymer Model?

From Dev

Polymer querySelector can't find custom polymer element in polymer element

From Dev

Polymer querySelector can't find custom polymer element in polymer element

From Dev

How can i drag a hidden child element

From Dev

Passing attribute to custom element in Polymer as a function

From Dev

Polymer/PolymerTS: Pass object to custom element

From Dev

How can I pass a template to a directive in an attribute?

From Dev

How can I focus on an element within an imported React component?

From Dev

How can I focus on an element within an imported React component?

From Dev

Jquery - How can i add a custom data attribute when appending an html element

From Dev

Styles applied to custom polymer element only inside an element with layout attribute

From Dev

How can I rewrite the native HTML input element with Polymer?

From Dev

How can I refresh/reload Polymer element, when page changes?

From Dev

how can i use a Polymer element after instantiating it?

From Dev

How can I rewrite the native HTML input element with Polymer?

From Dev

How can I refresh/reload Polymer element, when page changes?

From Dev

Polymer 1.0: How to pass an argument to a Polymer function from an attribute?

From Dev

Can I insert a custom attribute into a HTML element using Jquery?

From Dev

How to add function attribute to polymer element

Related Related

  1. 1

    How can i make custom Polymer element hidden?

  2. 2

    How can i make custom Polymer element hidden?

  3. 3

    How can I pass a Polymer Object beetwen 2 custom elements

  4. 4

    How to Bind Attribute from Custom Polymer Element to angularjs

  5. 5

    How can I trigger an event on an element in Polymer?

  6. 6

    How can I pass a wct test while rearranging children spans in a Polymer element?

  7. 7

    How to pass data from JavaScript code to Polymer custom element?

  8. 8

    DART POLYMER: How I can update a property from a custom element by another?

  9. 9

    Polymer 1: How can I set up paper-checkbox label dynamically using a custom element

  10. 10

    How can I handle paper-dropdown-close event in my custom polymer element

  11. 11

    How to update hidden$= attribute in a Polymer Model?

  12. 12

    Polymer querySelector can't find custom polymer element in polymer element

  13. 13

    Polymer querySelector can't find custom polymer element in polymer element

  14. 14

    How can i drag a hidden child element

  15. 15

    Passing attribute to custom element in Polymer as a function

  16. 16

    Polymer/PolymerTS: Pass object to custom element

  17. 17

    How can I pass a template to a directive in an attribute?

  18. 18

    How can I focus on an element within an imported React component?

  19. 19

    How can I focus on an element within an imported React component?

  20. 20

    Jquery - How can i add a custom data attribute when appending an html element

  21. 21

    Styles applied to custom polymer element only inside an element with layout attribute

  22. 22

    How can I rewrite the native HTML input element with Polymer?

  23. 23

    How can I refresh/reload Polymer element, when page changes?

  24. 24

    how can i use a Polymer element after instantiating it?

  25. 25

    How can I rewrite the native HTML input element with Polymer?

  26. 26

    How can I refresh/reload Polymer element, when page changes?

  27. 27

    Polymer 1.0: How to pass an argument to a Polymer function from an attribute?

  28. 28

    Can I insert a custom attribute into a HTML element using Jquery?

  29. 29

    How to add function attribute to polymer element

HotTag

Archive