2017-11-06 19:02:18 +01:00
< h1 class = "no-toc" > Tutorial: Tour of Heroes< / h1 >
2017-04-01 01:57:13 +02:00
2018-02-28 08:08:59 +08:00
< h1 class = "no-toc" > 教程:英雄指南< / h1 >
2017-07-30 14:10:08 +08:00
2019-03-20 15:10:47 +00:00
This _Tour of Heroes_ tutorial provides a deep dive into the fundamentals of Angular.
It shows you how to set up your local development environment and develop an app using the [Angular CLI tool ](cli "CLI command reference" ).
2017-04-01 01:57:13 +02:00
2019-06-02 22:29:53 +08:00
这个**英雄指南**教程深入讲解了 Angular 的基本知识。它向你展示了如何搭建本地开发环境,以及如何使用 [Angular CLI 工具 ](cli "CLI command reference" )开发一个应用。
2017-03-27 16:08:53 +01:00
2019-03-20 15:10:47 +00:00
< div class = "callout is-helpful" >
< header > Getting Started - Stackblitz< / header >
2019-06-02 22:29:53 +08:00
< header > 快速起步 - Stackblitz< / header >
2019-03-20 15:10:47 +00:00
We recently introduced a [**new Getting Started** ](getting-started ) that leverages the [StackBlitz ](https://stackblitz.com/ ) online development environment.
We recommend the new Getting Started for anyone who wants to quickly learn the essentials of Angular, in the context of building an online store app.
The new Getting Started covers the same major topics as this Tour of Heroes— components, template syntax, routing, services, and accessing data via HTTP— in a condensed format.
2019-06-02 22:29:53 +08:00
我们最近引入了一个[**新的快速上手** ](getting-started ),它基于在线开发环境 [StackBlitz ](https://stackblitz.com/ )。
我们建议每个想要快速掌握 Angular 基础知识的人使用那个新的快速上手,来构建一个在线商店应用程序。
新的快速上手以更精简的格式涵盖了与本《英雄指南》相同的主题:组件、模板语法、路由、服务以及通过 HTTP 访问数据等。
2019-03-20 15:10:47 +00:00
< / div >
In this _Tour of Heroes_ tutorial, you will build an app that helps a staffing agency manage its stable of heroes.
2019-06-02 22:29:53 +08:00
在这个**英雄指南**教程中,你将构建一个应用,来帮助招聘机构管理一群英雄。
2019-03-20 15:10:47 +00:00
This app has many of the features you'd expect to find in a data-driven application.
2017-11-06 19:02:18 +01:00
It acquires and displays a list of heroes, edits a selected hero's detail, and navigates among different views of heroic data.
2017-07-23 11:51:25 +08:00
2018-02-28 08:08:59 +08:00
这个入门级 app 包含很多数据驱动的应用所需的特性。
它需要获取并显示英雄的列表、编辑所选英雄的详情,并且在英雄数据的不同视图之间导航。
2017-02-22 18:09:39 +00:00
2019-03-20 15:10:47 +00:00
By the end of this tutorial you will be able to do the following:
2017-07-23 11:51:25 +08:00
2018-03-09 13:30:42 +08:00
在本教程的最后,你将完成下列工作:
2017-03-27 16:08:53 +01:00
2017-11-06 19:02:18 +01:00
* Use built-in Angular directives to show and hide elements and display lists of hero data.
2017-07-23 11:51:25 +08:00
2019-01-27 22:10:45 +08:00
使用Angular 的内置指令来显示 / 隐藏元素,并显示英雄数据的列表。
2018-03-03 21:06:01 +08:00
2017-11-06 19:02:18 +01:00
* Create Angular components to display hero details and show an array of heroes.
2017-02-22 18:09:39 +00:00
2018-03-03 21:06:01 +08:00
创建 Angular 组件以显示英雄的详情,并显示一个英雄数组。
2017-11-06 19:02:18 +01:00
* Use one-way data binding for read-only data.
2017-07-23 11:51:25 +08:00
2019-02-19 14:37:08 +08:00
为只读数据使用单向数据绑定。
2018-03-03 21:06:01 +08:00
2017-11-06 19:02:18 +01:00
* Add editable fields to update a model with two-way data binding.
2017-02-22 18:09:39 +00:00
2018-03-03 21:06:01 +08:00
添加可编辑字段,使用双向数据绑定来更新模型。
2017-11-06 19:02:18 +01:00
* Bind component methods to user events, like keystrokes and clicks.
2017-02-22 18:09:39 +00:00
2018-03-03 21:06:01 +08:00
把组件中的方法绑定到用户事件上,比如按键和点击。
2017-11-06 19:02:18 +01:00
* Enable users to select a hero from a master list and edit that hero in the details view.
2017-07-23 11:51:25 +08:00
2018-03-03 21:06:01 +08:00
让用户可以在主列表中选择一个英雄,然后在详情视图中编辑他。
2017-11-06 19:02:18 +01:00
* Format data with pipes.
2017-04-01 01:57:13 +02:00
2018-03-03 21:06:01 +08:00
使用管道来格式化数据。
2017-11-06 19:02:18 +01:00
* Create a shared service to assemble the heroes.
2018-02-28 08:08:59 +08:00
2018-03-03 21:06:01 +08:00
创建共享的服务来管理这些英雄。
2017-11-06 19:02:18 +01:00
* Use routing to navigate among different views and their components.
2017-02-22 18:09:39 +00:00
2018-03-03 21:06:01 +08:00
使用路由在不同的视图及其组件之间导航。
2018-02-28 08:08:59 +08:00
2017-11-06 19:02:18 +01:00
You'll learn enough Angular to get started and gain confidence that
Angular can do whatever you need it to do.
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
你将学到足够的 Angular 知识,并确信 Angular 确实能提供你所需的支持。
2018-03-03 21:06:01 +08:00
2019-03-20 15:10:47 +00:00
After completing all tutorial steps, the final app will look like this: < live-example name = "toh-pt6" > < / live-example > .
2017-04-01 01:57:13 +02:00
2018-02-28 08:08:59 +08:00
完成本教程的所有步骤之后,最终的应用会是这样的:< live-example name = "toh-pt6" > < / live-example > 。
2017-04-01 01:57:13 +02:00
2017-06-09 17:48:53 -04:00
## What you'll build
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
## 你要构建出什么
2017-07-23 11:51:25 +08:00
2017-03-27 16:08:53 +01:00
Here's a visual idea of where this tutorial leads, beginning with the "Dashboard"
view and the most heroic heroes:
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
下面是本教程关于界面的构想: 开始是“Dashboard( 仪表盘) ”视图, 来展示最勇敢的英雄。
2017-07-23 11:51:25 +08:00
2017-05-09 23:53:32 +01:00
< figure >
2018-03-03 21:06:01 +08:00
< img src = 'generated/images/guide/toh/heroes-dashboard-1.png' alt = "Output of heroes dashboard" >
2017-02-22 18:09:39 +00:00
< / figure >
2017-04-26 15:11:02 +03:00
You can click the two links above the dashboard ("Dashboard" and "Heroes")
2017-03-27 16:08:53 +01:00
to navigate between this Dashboard view and a Heroes view.
2017-02-22 18:09:39 +00:00
2017-07-23 11:51:25 +08:00
仪表盘顶部中有两个链接: “Dashboard( 仪表盘) ”和“Heroes( 英雄列表) ”。
2018-03-09 13:30:42 +08:00
你将点击它们在“仪表盘”和“英雄列表”视图之间导航。
2017-07-23 11:51:25 +08:00
2017-03-27 16:08:53 +01:00
If you click the dashboard hero "Magneta," the router opens a "Hero Details" view
where you can change the hero's name.
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
当你点击仪表盘上名叫“Magneta”的英雄时, 路由会打开英雄详情页, 在这里, 你可以修改英雄的名字。
2017-07-23 11:51:25 +08:00
2017-05-09 23:53:32 +01:00
< figure >
2018-03-03 21:06:01 +08:00
< img src = 'generated/images/guide/toh/hero-details-1.png' alt = "Details of hero in app" >
2017-02-22 18:09:39 +00:00
< / figure >
2017-03-27 16:08:53 +01:00
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.
2017-02-22 18:09:39 +00:00
2017-07-23 11:51:25 +08:00
点击“Back( 后退) ”按钮将返回到“Dashboard( 仪表盘) ”。
2018-03-09 13:30:42 +08:00
顶部的链接可以把你带到任何一个主视图。
2018-10-30 10:05:43 +08:00
如果你点击“Heroes( 英雄列表) ”链接, 应用将把你带到“英雄”列表主视图。
2017-07-23 11:51:25 +08:00
2017-05-09 23:53:32 +01:00
< figure >
2018-03-03 21:06:01 +08:00
< img src = 'generated/images/guide/toh/heroes-list-2.png' alt = "Output of heroes list app" >
2017-02-22 18:09:39 +00:00
< / figure >
2017-03-27 16:08:53 +01:00
When you click a different hero name, the read-only mini detail beneath the list reflects the new choice.
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
当你点击另一位英雄时,一个只读的“微型详情视图”会显示在列表下方,以体现你的选择。
2017-07-23 11:51:25 +08:00
2017-03-27 16:08:53 +01:00
You can click the "View Details" button to drill into the
editable details of the selected hero.
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
你可以点击“View Details( 查看详情) ”按钮进入所选英雄的编辑视图。
2017-07-23 11:51:25 +08:00
2017-03-27 16:08:53 +01:00
The following diagram captures all of the navigation options.
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
下面这张图汇总了所有可能的导航路径。
2017-07-23 11:51:25 +08:00
2017-05-09 23:53:32 +01:00
< figure >
2018-03-03 21:06:01 +08:00
< img src = 'generated/images/guide/toh/nav-diagram.png' alt = "View navigations" >
2017-02-22 18:09:39 +00:00
< / figure >
2017-03-27 16:08:53 +01:00
Here's the app in action:
2017-02-22 18:09:39 +00:00
2018-03-09 13:30:42 +08:00
下图演示了本应用中的动图。
2017-07-23 11:51:25 +08:00
2017-05-09 23:53:32 +01:00
< figure >
2018-03-03 21:06:01 +08:00
< img src = 'generated/images/guide/toh/toh-anim.gif' alt = "Tour of Heroes in Action" >
2017-02-22 18:09:39 +00:00
< / figure >