【发布时间】:2015-11-25 05:33:07
【问题描述】:
我正在尝试动态创建我创建的自定义组件的实例。我认为正确的方法是使用new Element.tag('custom-component');,但这会为我产生以下堆栈跟踪:
method not found: 'constructor' on null
my_component_test.dart.browser_test.dart.js 21834:17 J.$index$asx
my_component_test.dart.browser_test.dart.js 22460:14 <fn>
unparsed my_component_test.dart.browser_test.dart.js 22583:42 Isolate.prototype.(anonymous function)
my_component_test.dart.browser_test.dart.js 16549:24 dart._setUpPropertyChanged
my_component_test.dart.browser_test.dart.js 16521:28 $async$initPolymer
my_component_test.dart.browser_test.dart.js 3319:13 _wrapJsFunctionForAsync_closure._captured_protected_1
my_component_test.dart.browser_test.dart.js 4292:14 _wrapJsFunctionForAsync_closure.dart._wrapJsFunctionForAsync_closure.call$1
my_component_test.dart.browser_test.dart.js 5945:18 dart._rootRunUnary
my_component_test.dart.browser_test.dart.js 8620:41 _CustomZone.dart._CustomZone.runUnary$2
my_component_test.dart.browser_test.dart.js 6906:80 _Future__propagateToListeners_handleValueCallback.dart._Future__propagateToListeners_handleValueCallback.call$0
但是,使用Element.html('<custom-component></custom-component') 和覆盖的空TreeSanitizer,如此处所述http://japhr.blogspot.de/2013/11/dynamically-generating-polymerdart.html,一切正常并且测试通过:
class NullTreeSanitizer implements NodeTreeSanitizer {
void sanitizeTree(node) {}
}
componentUnderTest = new Element.html('<my-component></my-component>', treeSanitizer: new NullTreeSanitizer());
我的设置可能有什么问题?如果我禁用检查,该组件似乎已正确实现和注册。
【问题讨论】:
-
能否请您添加您的组件的代码和您的主要方法。问题是关于 Polymer 1.0?
-
这也是在 Firefox 中还是在 Dartium 中?
-
我正在使用聚合物 1.0.0-rc.6。它发生在 Linux 上的最新 Chrome 中。该代码在此 repo 中可用:github.com/flash1293/polymer_dart_example/tree/darttest
-
我还建议在每个依赖版本之前添加
^,然后您可以获得最新的可用版本,直到下一个“级别”。请参阅dartlang.org/tools/pub/dependencies.html#caret-syntax 我必须修改 pubspec.yaml 才能安装依赖项,因为您定义的版本与我的 Dart 版本(1.14 前沿)并不完全兼容。不过,对于生产来说,有严格的版本限制可能是有意义的。
标签: dart dart-polymer