why am I getting type error on polymer.dart element?

匆匆过客 提交于 2019-12-07 22:31:01

问题


I have some code:

// main.dart:
void main{
  initPolymer();
  var view = new ChatAppConsumer();
}

//chat_app.dart
@CustomTag('chat-app')
class ChatApp extends PolymerElement{
  ChatApp.created():super.created();
}

class ChatAppConsumer{
  final ChatApp view = new Element.tag('chat-app');
}

as far as I can tell I have all my files properly referenced and Im calling initPolymer(); before I attempt to create my custom tag, but I get the type error that the HtmlElement returned by new Element.tag('chat-app'); is not of typeChatApp` but I use this exact same pattern in another package I have and it works perfectly there. Anyone come across something like this before?


回答1:


initPolymer is not enough, you should pass a closure to initPolymer.run(() => ...) which executes your Polymer related code.

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

= Polymer 0.16.0 // main.dart: void main{ initPolymer().then((zone) => zone.run(() { var view = new ChatAppConsumer(); })); }

< Polymer 0.16.0

// main.dart:
void main{
  initPolymer().run(() {
    var view = new ChatAppConsumer();
  });
}


来源:https://stackoverflow.com/questions/26876713/why-am-i-getting-type-error-on-polymer-dart-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!