Я пытался следовать код найти здесь:Динамически добавлять WebComponent в Dart?
component_created_in_code_test.html
component_created_in_code.dart
Однако, когда я получаю зависимости и запустить код в dartium, я получаю следующее сообщение об ошибке. Эта ошибка возникает при вызове метода создания() из ComponentItem (в коде .dart):
Breaking on exception: Class 'SayHello' has no instance method 'created_autogenerated'.
Я переписал их чуть-чуть ниже (код идентичен, за исключением основной был перемещен, чтобы быть дротик код, а не встраиваемыми):
<!-- component_created_in_code_test.html -->
<!doctype html>
<!--
Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
for details. All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="packages/web_ui/testing/testing.js"></script>
</head>
<body>
<element name="say-hello">
<template>Hello {{name}}!</template>
<script type='application/dart' src="component_created_in_code.dart">
</script>
</element>
<say-hello name="component create in html"></say-hello>
</body>
</html>
и следующий код дротик,
//component_created_in_code.dart
library component_created_in_code;
import 'dart:async';
import 'dart:html';
import 'package:web_ui/web_ui.dart';
class SayHello extends WebComponent {
String name;
}
void main() {
Timer.run(() {
var hello = new SayHello()
..host = new DivElement()
..name = 'component created in code';
// "hello" is the DOM node.
// "hello.xtag" is your SayHello object.
// We are working on making these be the same object.
// If the component uses data-binding, we need to make sure the
// "lifecycle" methods get called. We are working to make this be
// automatic too.
var lifecycleCaller = new ComponentItem(hello)..create();
document.body.nodes.add(hello.host);
lifecycleCaller.insert();
window.postMessage('done', '*');
});
}
Казалось бы, что этот пример дротик-Ланг проблема. Я что-то пропустил или код просто укусил?
После ответа на этот вопрос я упаковал рабочее решение проблемы.
Просто вытащить из мерзавца, а затем импортировать в dartEditor. Затем «pub install» и «reanalyze source» (никогда не болит) из редактора, затем щелкните правой кнопкой мыши «Run in Dartium» на странице «web/component_created_in_code.html».
Стивен, я получил ниже ошибки при запуске вашего образца. Вы их тоже видите? "// @ sourceMapURL =" URL-адрес объявления сопоставления исходного текста устарел, вместо этого следует использовать объявление "# sourceMapURL =". "// @ sourceMapURL =" URL-адрес объявления сопоставления источника устарел, вместо этого следует использовать декларацию "# sourceMapURL =". FAIL Внутренняя ошибка: 'пакет: web_ui/web_ui.dart ': Ошибка: строка 137 pos 34: класс «WebComponent» переопределяет функцию «createInstance» суперкласса «Элемент» с несовместимыми параметрами DocumentFragment createInstance() => host.createInstance(); – Y2i
По какой-то причине у меня были старые библиотеки в папке пакетов даже после установки pub install. Выполняя эту пару раз, проблема решена, спасибо! – Y2i