How do I create a custom element in dart?

前端 未结 1 1084
遇见更好的自我
遇见更好的自我 2021-01-19 04:32

I am trying to make a custom element in dart. It should simply contain 2 buttons. It never actually makes it through the construction process...what am I doing wrong?

1条回答
  •  余生分开走
    2021-01-19 05:11

    There are a few issues in your code.

    • Custom elements need to follow the naming rules that they need to have a - in their name
    • The element needs to be registered in order for the browser to be able to instantiate them
    • The setup(...) method you added wasn't called, therefore not caption was added to the button
    • Custom elements need to extend HtmlElement

    DartPad example

    See also:

    • Registering custom element in Dart lang
    • extendTag in Dart custom element

    0 讨论(0)
提交回复
热议问题