html5 - Extending dart:html classes in dart -
i new dart , wonder if can, example, extend divelement class create custom elements in 1 line of code. looking this;
class redbox extends divelement { redbox(text) { this.text = text; this.style.background = "red"; } } redbox mybox = new redbox("hello world"); document.body.append(mybox);
of course have more complex elements custom functions. in general, possible?
when try run this, get:
implicit call super constructor 'divelement()'
you can extend html elements, there few requirements. 1 you're running need redbox.created
constructor, , can redirect super class. created
must generative constructor, though can add factory constructors.
another requirement element registered document.registerelement.
try adding this:
class redbox extends htmlelement { redbox.created() : super.created() { style.background = "red"; } factory redbox(text) => new element.tag('my-redbox')..text = text; } document.registerelement('my-redbox', redbox);
Comments
Post a Comment