1

I basically want to create a <core-tooltip> tag, not in HTML, but in dart.

So i tried:

CoreTooltip tooltip = new CoreTooltip();
CoreTooltip tooltip = document.createElement("core-tooltip"):
CoreTooltip tooltip = new Element.tag("core-tooltip"):

got always the same Exception

Uncaught Error: type 'HtmlElement' is not a subtype of type 'CoreTooltip'

Why does that just not work?

Azael
  • 614
  • 4
  • 16

1 Answers1

0

You shouldn't use this method

document.createElement("core-tooltip"):

the other two are fine though.

I assume the element creation fails because the code is in a custom main and is executed before Polymer is done with initialization.

See how to implement a main function in polymer apps for more details.

If you execute the code inside a Polymer elements (for example attached() method after super.attached()) or in an event handler like on-click this will work.

Another possibility is, that you app is missing an HTML import that imports <core-tooltip>. Without an import this can't work either.

I tried it with this code and it worked for me

app_element.dart

import 'dart:html' as dom;
import 'package:polymer/polymer.dart';
import 'package:core_elements/core_tooltip.dart';

@CustomTag('app-element')

class AppElement extends PolymerElement {

  AppElement.created() : super.created() {  }

  @PublishedProperty(reflect: true) bool isValidationError;

  void attached() {
    super.attached();
    CoreTooltip tt =  new CoreTooltip();
    print(tt);
  }
}

app_element.html

<link rel="import" href="../../packages/polymer/polymer.html">
<link rel="import" href="../../packages/core_elements/core_tooltip.html">

<polymer-element name="app-element">
  <template>
  </template>
  <script type="application/dart" src="app_element.dart"></script>
</polymer-element>
Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567