如何将一个angular2-dart包中的组件导入到另一个angular2-dart包中

How to import a component in one angular2-dart package into another angular2-dart package

我了解如何将一个 dart-polymer 包导入另一个包并使用导入包中的组件。

angular2-dart 好像有区别

我在 A 包中创建了一个 angular2-dart 组件并将其导入到 B 包中。 我要使用的特定组件是 NameComponent。

在 polymer 中,我只需执行以下操作即可使用导入组件的标记

<name-component></name-component>

做类似的事情在 angular2-dart 中不起作用。

我找不到有关将组件从一个 dart 包导入另一个 angular2-dart 的信息。

下面显示了我正在尝试执行的操作的图形摘要 - 程序包 B。名称组件来自程序包 A。

有人知道这是怎么做到的吗?

编辑 1

在进行了建议的更正后,我收到了以下内容

"P:\Program Files\Dart\dev\dart-sdk\bin\pub.bat" serve web --port=57435
Loading source assets...
Loading angular2 and dart_to_js_script_rewriter transformers...
Serving epimss_ng2_app web on http://localhost:57435
[DirectiveProcessor on epimss_ng2_reg|lib/components.dart]:
ERROR: Invalid argument (url): "Could not read asset at uri asset:epimss_ng2_reg/lib/name_component.html"
[Warning from TemplateCompiler on epimss_ng2_app|lib/app_component.ng_meta.json]:
Could not find Directive entry for name: NameComponent
. Please be aware that Dart transformers have limited support for reusable, pre-defined lists of Directives (aka "directive aliases"). See https://goo.gl/d8XPt0 for details.
Build completed with 1 errors.
[web] GET Served 13 assets.
[web] GET packages/epimss_ng2_reg/components.dart => Could not find asset epimss_ng2_reg|lib/components.dart.
[web] GET Served 17 assets.

我准备把components目录直接放到lib上看看有没有效果

我的包居然是packages/epimss_ng2_reg/src/components.dart.

我只能想到您可能遗漏的两件事。

  • 您需要将组件添加到指令中 @Component(..., directives: const [NameComponent]) 父组件。
  • 您需要在组件
  • pubspec.yaml 中添加 Angular2 转换器

transformers:
  angular2