# Conflicts: # aio/content/guide/ajs-quick-reference.md # aio/content/guide/animations.md # aio/content/guide/aot-compiler.md # aio/content/guide/attribute-directives.md # aio/content/guide/bootstrapping.md # aio/content/guide/browser-support.md # aio/content/guide/component-interaction.md # aio/content/guide/component-styles.md # aio/content/guide/dependency-injection-in-action.md # aio/content/guide/dependency-injection.md # aio/content/guide/deployment.md # aio/content/guide/displaying-data.md # aio/content/guide/form-validation.md # aio/content/guide/forms.md # aio/content/guide/glossary.md # aio/content/guide/http.md # aio/content/guide/i18n.md # aio/content/guide/ngmodule-faq.md # aio/content/guide/ngmodule.md # aio/content/guide/npm-packages.md # aio/content/guide/pipes.md # aio/content/guide/quickstart.md # aio/content/guide/reactive-forms.md # aio/content/guide/structural-directives.md # aio/content/guide/template-syntax.md # aio/content/guide/testing.md # aio/content/marketing/index.html # aio/content/navigation.json # aio/content/tutorial/index.md # aio/content/tutorial/toh-pt1.md # aio/content/tutorial/toh-pt2.md # aio/content/tutorial/toh-pt3.md # aio/content/tutorial/toh-pt4.md # aio/content/tutorial/toh-pt5.md # aio/content/tutorial/toh-pt6.md # aio/src/app/embedded/api/api-list.component.ts # aio/src/app/layout/doc-viewer/doc-viewer.component.ts # aio/src/app/layout/footer/footer.component.html # aio/src/app/layout/toc/toc.component.html # aio/src/app/search/search.service.ts # aio/src/styles/1-layouts/_marketing-layout.scss # aio/yarn.lock
134 lines
5.0 KiB
Markdown
134 lines
5.0 KiB
Markdown
<h1 class="no-toc">Tutorial: Tour of Heroes</h1>
|
||
|
||
<h1 class="no-toc">教程:英雄指南</h1>
|
||
|
||
The _Tour of Heroes_ tutorial covers the fundamentals of Angular.
|
||
In this tutorial you will build an app that helps a staffing agency manage its stable of heroes.
|
||
|
||
**英雄指南**教程涵盖了 Angular 的核心原理。在本教程中,我们将构建一个应用,来帮助招聘机构来管理一群英雄。
|
||
|
||
This basic app has many of the features you'd expect to find in a data-driven application.
|
||
It acquires and displays a list of heroes, edits a selected hero's detail, and navigates among different views of heroic data.
|
||
|
||
这个入门级 app 包含很多数据驱动的应用所需的特性。
|
||
它需要获取并显示英雄的列表、编辑所选英雄的详情,并且在英雄数据的不同视图之间导航。
|
||
|
||
By the end of the tutorial you will be able to do the following:
|
||
|
||
在本教程的最后,我们将完成下列工作:
|
||
|
||
* Use built-in Angular directives to show and hide elements and display lists of hero data.
|
||
|
||
使用内置指令来显示 / 隐藏元素,并且显示英雄数据的列表。
|
||
|
||
* Create Angular components to display hero details and show an array of heroes.
|
||
|
||
创建 Angular 组件以显示英雄的详情,并显示一个英雄数组。
|
||
|
||
* Use one-way data binding for read-only data.
|
||
|
||
为只读数据使用单项数据绑定。
|
||
|
||
* Add editable fields to update a model with two-way data binding.
|
||
|
||
添加可编辑字段,使用双向数据绑定来更新模型。
|
||
|
||
* Bind component methods to user events, like keystrokes and clicks.
|
||
|
||
把组件中的方法绑定到用户事件上,比如按键和点击。
|
||
|
||
* Enable users to select a hero from a master list and edit that hero in the details view.
|
||
|
||
让用户可以在主列表中选择一个英雄,然后在详情视图中编辑他。
|
||
|
||
* Format data with pipes.
|
||
|
||
使用管道来格式化数据。
|
||
|
||
* Create a shared service to assemble the heroes.
|
||
|
||
创建共享的服务来管理这些英雄。
|
||
|
||
* Use routing to navigate among different views and their components.
|
||
|
||
使用路由在不同的视图及其组件之间导航。
|
||
|
||
You'll learn enough Angular to get started and gain confidence that
|
||
Angular can do whatever you need it to do.
|
||
|
||
完成本教程后,我们将学到足够的 Angular 知识,并确信 Angular 确实能提供我们所需的支持。
|
||
|
||
After completing all tutorial steps, the final app will look like this <live-example name="toh-pt6"></live-example>.
|
||
|
||
完成本教程的所有步骤之后,最终的应用会是这样的:<live-example name="toh-pt6"></live-example>。
|
||
|
||
## What you'll build
|
||
|
||
## 我们要构建出什么
|
||
|
||
Here's a visual idea of where this tutorial leads, beginning with the "Dashboard"
|
||
view and the most heroic heroes:
|
||
|
||
下面是本教程关于界面的构想:开始是“Dashboard(仪表盘)”视图,来展示我们最勇敢的英雄。
|
||
|
||
|
||
<figure>
|
||
<img src='generated/images/guide/toh/heroes-dashboard-1.png' alt="英雄仪表盘的输出">
|
||
</figure>
|
||
|
||
You can click the two links above the dashboard ("Dashboard" and "Heroes")
|
||
to navigate between this Dashboard view and a Heroes view.
|
||
|
||
仪表盘顶部中有两个链接:“Dashboard(仪表盘)”和“Heroes(英雄列表)”。
|
||
我们将点击它们在“仪表盘”和“英雄列表”视图之间导航。
|
||
|
||
If you click the dashboard hero "Magneta," the router opens a "Hero Details" view
|
||
where you can change the hero's name.
|
||
|
||
当我们点击仪表盘上名叫“Magneta”的英雄时,路由将把我们带到这个英雄的详情页,在这里,我们可以修改英雄的名字。
|
||
|
||
|
||
<figure>
|
||
<img src='generated/images/guide/toh/hero-details-1.png' alt="英雄详情的输出">
|
||
</figure>
|
||
|
||
Clicking the "Back" button returns you to the Dashboard.
|
||
Links at the top take you to either of the main views.
|
||
If you click "Heroes," the app displays the "Heroes" master list view.
|
||
|
||
点击“Back(后退)”按钮将返回到“Dashboard(仪表盘)”。
|
||
顶部的链接可以把我们带到任何一个主视图。
|
||
如果我们点击“Heroes(英雄列表)”链接,应用将把我们带到“英雄”主列表视图。
|
||
|
||
|
||
<figure>
|
||
<img src='generated/images/guide/toh/heroes-list-2.png' alt="英雄列表的输出">
|
||
</figure>
|
||
|
||
When you click a different hero name, the read-only mini detail beneath the list reflects the new choice.
|
||
|
||
当我们点击另一位英雄时,一个只读的“微型详情视图”会显示在列表下方,以体现我们的选择。
|
||
|
||
You can click the "View Details" button to drill into the
|
||
editable details of the selected hero.
|
||
|
||
我们可以点击“View Details(查看详情)”按钮进入所选英雄的编辑视图。
|
||
|
||
The following diagram captures all of the navigation options.
|
||
|
||
下面这张图汇总了我们所有可能的导航路径。
|
||
|
||
|
||
<figure>
|
||
<img src='generated/images/guide/toh/nav-diagram.png' alt="查看导航">
|
||
</figure>
|
||
|
||
Here's the app in action:
|
||
|
||
下图演示了我们应用中的所有操作。
|
||
|
||
|
||
<figure>
|
||
<img src='generated/images/guide/toh/toh-anim.gif' alt="英雄指南的所有动作">
|
||
</figure>
|