Custom Polymer Element Extending AElement in Dart

I would like to create a custom Polymer element 'ab-btn' that extends the element 'a'. It should be used as:

<ab-btn href="http://www.gooogle.com">Google</ab-btn>

The declaration of the html element of the XML element looks like (the script is listed at the end because I want to declare more elements in one file):

<polymer-element name="ab-btn" extends="a">
  <template>
    <content></content>
  </template>
</polymer-element>

<script type="application/dart" src="ab-elements.dart"></script>

and dart script for the element:

import 'package:polymer/polymer.dart';
import 'dart:svg';

@CustomTag('ab-btn')
class AbBtn extends AElement {
  AbBtn.created() : super.created();

  var inputMethodContext;
}

When I try to use this element, I always get an error:

#13     _ZoneDelegate.run (dart:async/zone.dart:417)
#14     _CustomizedZone.run (dart:async/zone.dart:627)
#15     initPolymer (package:polymer/src/loader.dart:37:33)
#16     main (package:polymer/init.dart:23:22)


Exception: InvalidCharacterError: Internal Dartium Exception
  undefined (undefined:0:0)

What is the correct way to expand the 'a' elements?

+2
source share
1 answer

You must add using Polymer, Observable

@CustomTag('ab-btn')
class AbBtn extends AElement with Polymer, Observable {
  AbBtn.created() : super.created() {
    super.polymerCreated(); // <== also important for elements that extend DOM elements
  }
}

When you use the item

<a is="ab-btn" href="http://www.gooogle.com">Google</a>

or create an element by code:

var elm = new Element.tag('a', 'ab-btn');
+2
source

Source: https://habr.com/ru/post/1534714/


All Articles