Angular 角镖和APPDART模块
我正试图把AngularDart应用程序放在一起,我会在文档上来回移动 在AngularDart官方网站架构页面中,它讨论了非常重要的AppModule 然而,这是唯一提到模块的地方。在所有其他地方(包括示例代码和教程),AppModule完全缺失,尽管架构指南页面坚持至少需要一个模块Angular 角镖和APPDART模块,angular,dart,angular-dart,Angular,Dart,Angular Dart,我正试图把AngularDart应用程序放在一起,我会在文档上来回移动 在AngularDart官方网站架构页面中,它讨论了非常重要的AppModule 然而,这是唯一提到模块的地方。在所有其他地方(包括示例代码和教程),AppModule完全缺失,尽管架构指南页面坚持至少需要一个模块 有人能澄清这一点吗?从概念上讲,AppModule不是一个具体的东西,它只是为应用程序设置的“根级依赖注入服务”。有些应用程序可能没有,有些可能有很多 您会注意到,在我们的github_问题示例应用程序中,“A
有人能澄清这一点吗?从概念上讲,
AppModule
不是一个具体的东西,它只是为应用程序设置的“根级依赖注入服务”。有些应用程序可能没有,有些可能有很多
您会注意到,在我们的github_问题示例应用程序中,“AppModule”中有一项服务:
导入“包:角度/角度.dart”;
导入“package:examples.github_issues/api.dart”;
导入“package:examples.github_issues/ui.dart”;
将“main.template.dart”作为ng导入;
@组成部分(
选择器:“ng应用程序”,
指令:const[
发布列表组件,
],
模板:“”,
)
类NgAppComponent{}
void main(){
bootstrapStatic(
Ngappy组件,
常数[
常量类提供程序(GithubService),
],
吴荣奎,
);
}
。。。GithubService
。此应用程序中承载的任何组件(或服务)都可以访问它
这有帮助吗?对Angular module模式以及如何在实际Angular应用程序中组织主模块和功能模块进行了很好的解释
您将按照以下要求组织危机中心
角度应用程序的推荐模式:
- 每个要素区域都位于其自己的文件夹中
- 每个区域都有自己的区域根组件
- 每个区域根组件都有自己的路由器出口和子路由
- 区域路线很少(如果有)交叉
AppModule
本身是一个精简组件,如果您愿意,它是应用程序的中心集线器。它充当非终端功能模块路由和应用程序范围服务的容器。与上面链接的文档类似:
@Component(
selector: 'my-app',
template: '''
<h1>Angular Router</h1>
<nav>
<a [routerLink]="['CrisisCenter']">Crisis Center</a>
<a [routerLink]="['Heroes']">Heroes</a>
</nav>
<router-outlet></router-outlet>
''',
styles: const ['.router-link-active {color: #039be5;}'],
directives: const [ROUTER_DIRECTIVES],
providers: const [HeroService],
)
@RouteConfig(const [
const Redirect(path: '/', redirectTo: const ['Heroes']),
const Route(
path: '/crisis-center/...',
name: 'CrisisCenter',
component: CrisisCenterComponent),
const Route(path: '/heroes', name: 'Heroes', component: HeroesComponent),
const Route(
path: '/hero/:id', name: 'HeroDetail', component: HeroDetailComponent),
const Route(path: '/**', name: 'NotFound', component: NotFoundComponent)
])
class AppComponent {}
@组件(
选择器:“我的应用程序”,
模板:“”
角形路由器
危机中心
英雄
''',
样式:const['.router link active{color:#039be5;}'],
指令:const[ROUTER_指令],
提供者:const[HeroService],
)
@路由图(常数)[
常量重定向(路径:'/',重定向到:常量['Heroes']),
常量路线(
路径:“/危机中心/…”,
名称:“CrisCenter”,
组件:CrisCenter组件),
常量路由(路径:'/HERONES',名称:'HERONES',组件:HeroesComponent),
常量路线(
路径:'/hero/:id',名称:'HeroDetail',组件:HeroDetailComponent),
常量路由(路径:'/**',名称:'NotFound',组件:NotFoundComponent)
])
类AppComponent{}
@Component(
selector: 'my-app',
template: '''
<h1>Angular Router</h1>
<nav>
<a [routerLink]="['CrisisCenter']">Crisis Center</a>
<a [routerLink]="['Heroes']">Heroes</a>
</nav>
<router-outlet></router-outlet>
''',
styles: const ['.router-link-active {color: #039be5;}'],
directives: const [ROUTER_DIRECTIVES],
providers: const [HeroService],
)
@RouteConfig(const [
const Redirect(path: '/', redirectTo: const ['Heroes']),
const Route(
path: '/crisis-center/...',
name: 'CrisisCenter',
component: CrisisCenterComponent),
const Route(path: '/heroes', name: 'Heroes', component: HeroesComponent),
const Route(
path: '/hero/:id', name: 'HeroDetail', component: HeroDetailComponent),
const Route(path: '/**', name: 'NotFound', component: NotFoundComponent)
])
class AppComponent {}