mjs
mjs

Reputation: 65373

How to programmatically instantiate a Polymer element?

Is there some way to programmatically create a Polymer element that has no manifestation in the DOM, such as <polymer-ajax>?

I'm interested in this because doing Ajax requests via <polymer-ajax> is annoying in situations where you're doing something like:

  1. Generate a URL
  2. Retrieve URL (asynchronously)
  3. Manipulate the response

Upvotes: 2

Views: 1259

Answers (1)

ebidel
ebidel

Reputation: 24119

You can instantiate custom elements just as you can existing native HTML elements. Have you tried var el = document.createElement('polymer-ajax');? The only (potential) gotcha with Polymer elements is that its special features like {{}} bindings and *Changed handlers get cleaned up over time if the element is never added to the DOM.

http://www.polymer-project.org/polymer.html#bindings

Upvotes: 4

Related Questions