Questions tagged [polymer-2.x]

Polymer 2.x is designed to support the new custom elements v1 and shadow DOM v1 specifications being implemented by most major browser vendors, while providing a smooth migration path for Polymer 1.x users.

Polymer 2.x also makes improvements in several areas:

  • Improved interoperability. By removing the need to use Polymer.dom for DOM manipulation, Polymer 2.0 makes it easier to use Polymer components with other libraries and frameworks. In addition, the shady DOM code has been separated out into a reusable polyfill, instead of being integrated into Polymer.

  • Data system improvements. Polymer 2.0 includes targeted improvements to the data system. These changes make it easier to reason about and debug the propagation of data through and between elements. They also improve compatibility with top-down data flow approaches, like Flux.

  • More standard. Polymer 2.x uses standard ES6 classes and the standard custom elements v1 methods for defining elements, instead of a Polymer factory method. You can mix in features using standard JavaScript (class expression mixins) instead of Polymer behaviors. (The Polymer factory method is still supported using a compatibility layer.)


Example:

HTML:my-element.html

<!-- import polymer-element -->
<link rel="import"  href="https://polygit.org/components/polymer/polymer-element.html">

<dom-module id="my-element">

  <template>
        <style>
              /* scoped CSS rules for this element */
        </style>
        <!-- local DOM for your element -->
        <p>I'm a DOM element. This is my shadow DOM!</p>

        <!-- bind to the "owner" property -->
        This is <b>[[owner]]</b>'s creation.
  </template>

  <script>
    // Define the class for a new element called custom-element
    class MyElement extends Polymer.Element {

      static get is() { return "my-element"; }

      // configure owner property
      static get properties() {
        return {
          owner: {
            type: String,
            value: "Google",
          }
        };
      }

    }
    // Register the new element with the browser
    customElements.define(MyElement.is, MyElement );
  </script>

</dom-module>

Using my-element in other document:

<!-- Add the <link> tag in the head/top of your markup -->
<link rel="import" href="my-element.html">

<!-- Use your new element anywhere in the document -->
<my-element></my-element>

Source

More Examples

799 questions
17
votes
3 answers

How to create a component without using the Shadow DOM?

I am trying to create a component that does not have a Shadow DOM. Yeah, I know, Shadow DOM is great and all and is one of the main focuses of Web Components. But, let's say I wanted a component's styles to inherit from a parent. With Shadow…
Aaron Brewer
  • 3,567
  • 18
  • 48
  • 78
15
votes
1 answer

Debouncer in Polymer 2.0

Simple question, but no documentation is to be found on the subject : is there a debouncer in Polymer 2.0? If so, how can it be used? this.debounce was an instance method in 1.0, but it appears to have disappeared. Thanks in advance!
CedricLaberge
  • 592
  • 2
  • 7
  • 22
13
votes
3 answers

Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry' (Polymer 2.0)

I'm facing this issue while running polymer init on polymer-cli. Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry'
navnit kapadiya
  • 179
  • 1
  • 1
  • 9
11
votes
4 answers

Best way to communicate between instances of the same web component with Polymer?

I'm trying to sync some of my web component properties between instances of the same element so if one of this properties changes then the same property gets updated in all the instances with the corresponding binding and events. Note: I want to use…
AlbertoFdzM
  • 1,023
  • 11
  • 24
10
votes
1 answer

Lighthouse & Polymer: start_url in manifest is not cached by Service Worker

I'm testing my Polymer application and I get a pretty good score on Lighthouse. However, I still have a small problem. I have a manifest.json file containing everything so the app can be added to the home screen, but Lighthouse still gives a failure…
9
votes
3 answers

Correct way to use Polymer 2 elements in Polymer 3 element?

How can I use Polymer 2 elements in Polymer 3 element? The following doesn't work since element doesn't work inside shadow dom. static get template() { return '
Kibeom Kim
  • 471
  • 1
  • 5
  • 12
8
votes
1 answer

vaadin-grid-filter for an Array of Strings not working

I am using the vaadin-grid-filter with Polymer 2.x and I am facing the following problem. I have a vaadin-grid-column as following,