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
5
votes
1 answer

Polymer dynamic element name in dom-repeat

how can I use dom-repeat to create different elements for iron-pages? something like this: ... pages: { type: Array, value() { return [ { …
Zvi Karp
  • 3,621
  • 3
  • 25
  • 40
4
votes
1 answer

Disable entire month in vaadin date picker

I am trying to disable all dates of all months in vaadin-date-picker. While looking through the code, I found that I can individually disable dates by setting disabled in vaadin-month-calendar.html#L75 . In that case the disabled date is faded,…
Sudipta Roy
  • 740
  • 1
  • 9
  • 29
4
votes
1 answer

Polymer - format date in binded value

I have a tile inside a template and I want it to show a date: Where date is a property of the element: date: { type: Date, } This will however display the…
lte__
  • 7,175
  • 25
  • 74
  • 131
4
votes
0 answers

Advanced Polymer routing

I'm trying to build a Polymer web-app. I've followed the examples, read the documentation, and understand the starter-kits. The problem is I have no idea how to go beyond the examples. In particular - app-routing. I have a basic app structure in…
4
votes
2 answers

Web Driver click on element within ShadowDOM is returning error "{"message":"unknown error: Cannot read property 'defaultView' of undefined"

I have a website built with Polymer 2 with a DOM structure that looks like: ... #shadow-root (open)
4
votes
1 answer

Polymer DomModule already defined

I'm building a website, where I'd use different polymer components, some of them multiple times. My problem is that the compiled code contains a customElements.define('dom-module', DomModule); that throws Uncaught DOMException: Failed to…
csomakk
  • 5,369
  • 1
  • 29
  • 34
4
votes
0 answers

Polymer 2: routing from views and custom elements

I'm migrating an existing Polymer-based application to Polymer 2, and one thing the Polymer 2 upgrade guide is annoyingly silent about is how to update the routing code to work with the updated app-route and all its "routing encapsulation"…
Guss
  • 30,470
  • 17
  • 104
  • 128
4
votes
3 answers

Polymer 2.0 getElementById in different ShadowDom

I'm trying to learn Polymer 2.0 but am stuck with the problem of getting an element from a different Shadow Dom. This worked in Polymer 1 but no longer in Polymer 2.0. What is the correct way of writing this? It just tells me that the targetText =…
Vims
  • 157
  • 1
  • 8
4
votes
1 answer

Sass won't compile variable if property starts with double dash

I have updated the sass ruby gem to the latest version. Now when compiling .scss files the compiler won't replace the variables by its values if the property name before the variable (the property's value) starts with double dash --: Example…
Aquaguy
  • 357
  • 2
  • 11
4
votes
2 answers

ReferenceError: KeyframeEffect is not defined in paper component

I am building a web application, and for a dropdown list I am using a paper-dropdown-menu My code is quit simple, and closely follows the demo presented here Here is a snippet of the code:
jlengrand
  • 12,152
  • 14
  • 57
  • 87
4
votes
1 answer

Response for preflight 403 forbidden

I've been trying to make a simple iron-ajax post to the server, but it keeps failing at the preflight call. For the life of me I can't figure out what's going on, all the CORS headers seem to be correct on the server. Response…
DVM
  • 1,229
  • 3
  • 16
  • 22
4
votes
2 answers

Polymer 2.0 - Trying to implement HTML5 drag and drop

I am trying to implement HTML5 drag and drop for polymer2.0 components similar to the drag and drop option as in http://jsfiddle.net/U55rc/ HTML:
Naga Sai A
  • 10,771
  • 1
  • 21
  • 40
4
votes
0 answers

How to use Polymer JS without polymer-cli?

Polymer working well with polymer-cli but is any way to run polymer application without polymer-cli and how we integrate it with struts, grails frameworks?
Prakash Bhavnath
  • 269
  • 2
  • 10