为什么我在polymer.dart元素得到类型错误? [英] why am I getting type error on polymer.dart element?

查看:87
本文介绍了为什么我在polymer.dart元素得到类型错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码:

// 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 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?

推荐答案

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
// main.dart:
void main {
initPolymer()。 then((zone)=> zone.run((){
var view = new ChatAppConsumer();
}));
}

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

< Polymer 0.16.0

< Polymer 0.16.0

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

这篇关于为什么我在polymer.dart元素得到类型错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆