我正在尝试将 AngularDart 应用程序放在一起,并且我会在文档中来回查看。
在 AngularDart 官方站点架构页面中,它讨论了最重要的 AppModule
但是,这是唯一提到模块的地方。在所有其他地方 - 包括示例代码和教程,AppModule 完全缺失 - 尽管架构指南页面坚持认为至少需要一个模块。
有知情者可以解释一下吗?
最佳答案
从概念上讲,AppModule
并不是一个具体的东西,它只是您为应用程序设置的“根级依赖项注入(inject)服务”。有些应用程序可能没有,有些应用程序可能有很多。
您会注意到在我们的 github_issues 示例应用程序中,我们的“AppModule”中有一项服务:
https://github.com/dart-lang/angular/blob/master/examples/github_issues/web/main.dart
import 'package:angular/angular.dart';
import 'package:examples.github_issues/api.dart';
import 'package:examples.github_issues/ui.dart';
import 'main.template.dart' as ng;
@Component(
selector: 'ng-app',
directives: const [
IssueListComponent,
],
template: '<issue-list></issue-list>',
)
class NgAppComponent {}
void main() {
bootstrapStatic(
NgAppComponent,
const [
const ClassProvider(GithubService),
],
ng.initReflector,
);
}
...GithubService
。此应用程序中托管的任何组件(或服务)都可以访问它。
这有帮助吗?
关于AngularDart 和 AppModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49309126/