registerElement2 method Null safety

  1. @deprecated
Function registerElement2(
  1. String tag,
  2. [Map? options]
)
override

Deprecated: This is a legacy API based on a deprecated Web Components v0.5 specification. This method doesn't work on modern browsers and can only be used with a polyfill.

The latest Web Components specification is supported indirectly via JSInterop and doesn't have an explicit API in the dart:html library.

Original documentation before deprecation:

Register a custom subclass of Element to be instantiatable by the DOM.

This is necessary to allow the construction of any custom elements.

The class being registered must either subclass HtmlElement or SvgElement. If they subclass these directly then they can be used as:

class FooElement extends HtmlElement{
   void created() {
     print('FooElement created!');
   }
}

main() {
  document.registerElement('x-foo', FooElement);
  var myFoo = new Element.tag('x-foo');
  // prints 'FooElement created!' to the console.
}

The custom element can also be instantiated via HTML using the syntax <x-foo></x-foo>

Other elements can be subclassed as well:

class BarElement extends InputElement{
   void created() {
     print('BarElement created!');
   }
}

main() {
  document.registerElement('x-bar', BarElement);
  var myBar = new Element.tag('input', 'x-bar');
  // prints 'BarElement created!' to the console.
}

This custom element can also be instantiated via HTML using the syntax <input is="x-bar"></input>

Implementation

@deprecated
Function registerElement2(String tag, [Map? options]) {
  return _registerCustomElement(JS('', 'window'), this, tag, options);
}