Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
布线时将AngularDart组件放入子文件夹_Dart_Angular Dart_Angular Dart Routing - Fatal编程技术网

布线时将AngularDart组件放入子文件夹

布线时将AngularDart组件放入子文件夹,dart,angular-dart,angular-dart-routing,Dart,Angular Dart,Angular Dart Routing,根据,在为Dart定义角度布线时,需要导入相关组件的模板.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.d

根据,在为Dart定义角度布线时,需要导入相关组件的
模板.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;
lib/src/components/Foobar/foorbar\u component.dart
中的Foobar组件

当我在
src
中有
foobar\u组件.dart
code(即与
routes.dart
相同的文件夹)时,没有问题。但当我将其移动到其自己的子文件夹时,会出现以下错误:

无法找到某些源的模块[…]请检查以下导入:
import'components/foobar/foobar\u component.template.dart'

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

您可以使用

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
是在您的
pubspec.yaml的
name:…
中使用的字符串,导入文件的路径中跳过
lib/

我尝试了导入web:src/components/…
但出现错误“不支持的操作:无法解析web:src/components/[…];仅支持“包”和“资产”方案,“您是否将项目命名为
web
?提出具体建议有点困难,因为你的问题只提供了部分路径。如果要为导入和导入文件添加完整路径(相对于包含
pubspec.yaml
的目录,我可能能够提出更好的建议。是的,项目名为
web
pubspec.yaml
在根目录中。
routes.dart
lib/src
中,组件在
lib/src/components/[name]
中。对不起,我的错误我更新了我的答案。