问题描述
我有一些代码:
// 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');
}
我可以告诉我所有的文件正确引用和Im调用 initPolymer();
之前,我尝试创建我的自定义标记,但我得到的类型错误HtmlElement返回 new Element.tag -app');不是类型
ChatApp`,但我使用这个完全相同的模式在另一个包,我有,它的工作完美。任何人都会遇到类似这样的情况?
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 type
ChatApp` but I use this exact same pattern in another package I have and it works perfectly there. Anyone come across something like this before?
推荐答案
initPolymer
,您应该将一个闭包传递给 initPolymer.run(()=> ...)
,它会执行您的Polymer相关代码。
initPolymer
is not enough, you should pass a closure to initPolymer.run(() => ...)
which executes your Polymer related code.
请参阅了解更多详情
< Polymer 0.16.0
< Polymer 0.16.0
// main.dart:
void main{
initPolymer().run(() {
var view = new ChatAppConsumer();
});
}
这篇关于为什么我在polymer.dart元素得到类型错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!