聚合物querySelector在DartVM上工作,但编译后不在Chrome中 [英] Polymer querySelector working on DartVM but not in Chrome after compile
问题描述
有一个奇怪的问题。在我的Dart代码中,我在屏幕上有一些聚合物组件,其中一个有我从main()调用的方法。
Having a weird issue. In my Dart code I have some polymer components on the screen and one of them has a method I call from my main().
我通过做
PolyComp poly = querySelector("#idOfPolymer");
poly.flash();
这在dart中完美地工作。页面加载并且PolyComp开始闪烁。但是,当我通过从Dart IDE运行Build Polymer应用程序在Chrome中运行这个程序时,我得到一个错误,说无法在null上调用flash()。
This works perfectly in dart. The page loads up and PolyComp starts to flash. However when I run this in Chrome by running Build Polymer app from the Dart IDE, I get an error that says cannot call flash() on null.
它只是使用一个事件总线闪光,让PolyComp听我的事件,但这是过度杀伤。
I ended up making it flash by just using an event bus and letting PolyComp listen to my event, but this is overkill.
我做错了什么?这发生在最新的Chrome,Firefox和Safari中。
What am I doing wrong? This happens in the latest Chrome, Firefox and Safari.
编辑:
JS也碰到了同样的问题。
https:// github .com / sethladd / dart-polymer-dart-examples / blob / master / web / todo_element / todo.html
I built the following polymer app to JS also and ran into the same issue. https://github.com/sethladd/dart-polymer-dart-examples/blob/master/web/todo_element/todo.html
适用于DartVM因为它调用一个空元素上的方法。
Works on DartVM, not in Chrome because its calling a method on a null element.
推荐答案
当你从 main )
方法,这可能是一个时间问题。
您可以尝试类似
When you run this code from the main()
method it is probably a timing issue.
You can try something like
import "package:polymer/polymer.dart";
main() {
initPolymer().run(() {
// code here works most of the time
Polymer.onReady.then((e) {
// some things must wait until onReady callback is called
});
});
}
这篇关于聚合物querySelector在DartVM上工作,但编译后不在Chrome中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!