Tutorial: Tour of Heroes


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.


What you'll build


Here's a visual idea of where this tutorial leads, beginning with the "Dashboard" view and the most heroic heroes:


Output of heroes dashboard

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.


Details of hero in app

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(英雄列表)”链接,应用将把你带到“英雄”列表主视图。

Output of heroes list app

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.


View navigations

Here's the app in action:


Tour of Heroes in Action