AngularDart 中的 somecomponent.template.dart import 指向什么?

What does somecomponent.template.dart import in AngularDart point to?

我刚刚阅读 AngularDart routing tutorial 并偶然发现了这段代码。

import 'package:angular/angular.dart';
import 'package:angular_router/angular_router.dart';

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

@Injectable()
class Routes {
  static final _crises = new RouteDefinition(
    routePath: paths.crises,
    component: clct.CrisisListComponentNgFactory,
  );

  static final _heroes = new RouteDefinition(
    routePath: paths.heroes,
    component: hlct.HeroListComponentNgFactory,
  ); ..... see routing tutorial link above.
}

什么是

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

实际导入?

Angular 使用代码生成从 Angular 模板语法生成 Dart 代码。

这些组件导入生成的代码。 该代码包含路由器创建组件实例所需的工厂方法。

如果你有

import 'crisis_list_component.dart';

然后代码生成会额外生成一个

import 'crisis_list_component.template.dart' as clct;

在本例中是使用别名导入的 clct

The Angular compiler generates component factories behind the scenes when you build the app. To access the factory you need to import the generated component template file. Until you’ve built the app, the generated files don’t exist

来源:Jaimeloeuf's Medium publication

请注意,您可以在 project.dart_tools/build/generated 路径内的项目文件夹中找到它。