编译为javascript时,Polymer.dart遇到一些非常奇怪的问题。它在Dartium中运行良好。这个应用程式在几个月前确实运作正常。但是,从那时起,Polymer经历了许多更改,因此我不得不进行大量更改才能使其得以编译。我已经在Polymer 3.2到最新的pub中进行了尝试,所有行为都相同。我正在稳定分支上运行最新的Dart安装。
我收到以下Javascript错误:
TypeError: $document.register is not a function
在下面的js的最后一行。标签变量是“聚合物元素”。
})(H.convertDartClosureToJS(W._callAttributeChanged$closure(), 4)))};
proto = Object.create(baseConstructor.prototype, properties);
t2 = H.makeLeafDispatchRecord(interceptor);
Object.defineProperty(proto, init.dispatchPropertyName, {value: t2, enumerable: false, writable: true, configurable: true});
options = {prototype: proto};
if (!t1)
options.extends = extendsTagName;
$document.register(tag, options);
从我看到的结果来看,polyfills没有被加载,因此未声明document.register方法。
下面是我的HTML文件
<head>
<script src="index.dart" type="application/dart"></script>
<script src="packages/browser/dart.js"></script>
<script src="packages/browser/interop.js"></script>
</head>
我的index.dart看起来像
void main() {
window.alert("Dart Lives!");
initPolymer().run(() => initPresentation());
}
void initPresentation() {
//Show the first screen
}
在Javascript下运行时,出现警告框,并显示Javascript错误。因此,我认为基本的 Dart 环境没有任何问题。
最佳答案
编辑
这已经改变了。
最新答案在这里
Polymer querySelector working on DartVM but not in Chrome after compile
OLD
很难说。
我认为index.dart
应该看起来像
<head>
<script type='application/dart'>
export 'index.dart';
</script>
</head>
要么
<body>
...
<script type='application/dart' src='index.dart'></script>
</body>
见https://code.google.com/p/dart/issues/detail?id=17546#c16
关于dart - 编译为JavaScript时不加载Polymer.dart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21341825/