dart - Dart 自定义元素中的extendTag

标签 dart dart-html

来自this link在javascript中,自定义元素扩展按钮制作为:

var MegaButton = document.registerElement('mega-button', {
  prototype: Object.create(HTMLButtonElement.prototype),
  extends: 'button'
});

<button is="mega-button">

我尝试使用 dart 通过以下代码进行相同的操作:

class MegaButton extends ButtonElement  {
static final tag = 'mega-button';
factory MegaButton()=>new Element.tag('button', tag);  
   MegaButton.created() : super.created() { 
       var shadow = this.createShadowRoot();
       shadow.text='save';
  }
}
 document.registerElement(MegaButton.tag, MegaButton);

在html文件中

    <button  is="mega-button"></button>
    <mega-button>click me</mega-button>

但出现此错误:

Exception: Unsupported operation: Class must provide extendsTag if base native class is not HTMLElement

请提供任何帮助。谢谢

最佳答案

document.registerElement 应该如下所示:

document.registerElement(MegaButton.tag, MegaButton, extendsTag: 'button');
=> new Element.tag('button', tag);

另请参阅Custom Polymer element extending AElement in Dart

关于dart - Dart 自定义元素中的extendTag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26314402/

相关文章:

design-patterns - 是否可以对 Flutter 中的不同小部件使用具有抽象层的多态性?

flutter - 如何在 InheritedWidget 中调用 setState 或更新值?

flutter - Flutter可重复使用的文本字段及其样式

dart - 如何运行angulardart应用程序?

dart - 运行测试时加载 dartium 失败

css - onClick背景颜色变化

debugging - 如何在WebStorm中设置Dart调试?

dart - 如何在 Dart 中对 MappedListIterable 进行排序

dart - 在Dart中收听JS CustomEvent

dart - Dart Web套接字中是否有心跳,超时或断开连接支持?