代码之家  ›  专栏  ›  技术社区  ›  GluePear

路由时将AngularDart组件放入子文件夹

  •  1
  • GluePear  · 技术社区  · 6 年前

    根据 this tutorial ,在定义省道的角度路由时,需要导入 template.dart 相关组件的文件:

    import 'crisis_list_component.template.dart' as clct;
    import 'hero_list_component.template.dart' as hlct;
    

    我已经将我的组件放在该代码所在文件夹的子文件夹中。我有进口代码 lib/src/routes.dart :

    import 'components/foobar/foobar_component.template.dart' as fct;
    

    和foobar组件 lib/src/components/foobar/foorbar_component.dart .

    当我拥有 foobar_component.dart 代码在 src (即与 routes.dart )没问题。但是当我把它移到它自己的子文件夹时,我会得到一个错误:

    找不到某些源的模块[…]请检查以下导入: import 'components/foobar/foobar_component.template.dart'

    如何让它在其子文件夹中找到组件?

    1 回复  |  直到 6 年前
        1
  •  3
  •   James Jensen    6 年前

    你可以用

    import '../../components/foobar/foobar_component.template.dart' as fct;
    

    但通常最好不要用 ../ 在导入中,而是使用包导入

    import 'package:my_package/web/src/components/foobar/foobar_component.template.dart' as fct;
    

    在哪里? my_package 字符串是否用于 name: ... 在你 pubspec.yaml lib/ 在导入文件的路径中跳过。