@title
The Hero Editor
@intro
We build a simple hero editor.
@description
## Setup to develop locally
Real application development takes place in a local development environment like your machine.
Follow the [setup](guide/setup) instructions for creating a new project
named
after which the file structure should look like this:
angular-tour-of-heroes
src
app
app.component.ts
app.module.ts
main.ts
index.html
styles.css
systemjs.config.js
tsconfig.json
node_modules ...
package.json
When we're done with this first episode, the app runs like this .
## Keep the app transpiling and running
We want to start the TypeScript compiler, have it watch for changes, and start our server.
Do this by entering the following command in the terminal window.
npm start
This command runs the compiler in watch mode, starts the server, launches the app in a browser,
and keeps the app running while we continue to build the Tour of Heroes.
## Show our Hero
We want to display Hero data in our app
Update the `AppComponent` so it has two properties: a `title` property for the application name and a `hero` property
for a hero named "Windstorm".
{@example 'toh-1/ts-snippets/app.component.snippets.pt1.ts' region='app-component-1'}
Now update the template in the `@Component` decoration with data bindings to these new properties.
{@example 'toh-1/ts-snippets/app.component.snippets.pt1.ts' region='show-hero'}
The browser should refresh and display our title and hero.
The double curly braces tell our app to read the `title` and `hero` properties from the component and render them.
This is the "interpolation" form of one-way data binding.
Learn more about interpolation in the [Displaying Data chapter](guide/displaying-data).### Hero object
At the moment, our hero is just a name. Our hero needs more properties.
Let's convert the `hero` from a literal string to a class.
Create a `Hero` class with `id` and `name` properties.
For now put this near the top of the `app.component.ts` file, just below the import statement.
{@example 'toh-1/ts/src/app/app.component.ts' region='hero-class-1'}
Now that we have a `Hero` class, let’s refactor our component’s `hero` property to be of type `Hero`.
Then initialize it with an id of `1` and the name, "Windstorm".
{@example 'toh-1/ts/src/app/app.component.ts' region='hero-property-1'}
Because we changed the hero from a string to an object,
we update the binding in the template to refer to the hero’s `name` property.
{@example 'toh-1/ts-snippets/app.component.snippets.pt1.ts' region='show-hero-2'}
The browser refreshes and continues to display our hero’s name.
### Adding more HTML
Displaying a name is good, but we want to see all of our hero’s properties.
We’ll add a `
` for our hero’s `id` property and another `
` for our hero’s `name`.
{@example 'toh-1/ts-snippets/app.component.snippets.pt1.ts' region='show-hero-properties'}
Uh oh, our template string is getting long. We better take care of that to avoid the risk of making a typo in the template.
### Multi-line template strings
We could make a more readable template with string concatenation
but that gets ugly fast, it is harder to read, and
it is easy to make a spelling error. Instead,
let’s take advantage of the template strings feature
in ES2015 and TypeScript to maintain our sanity.
Change the quotes around the template to back-ticks and
put the `
`, `
` and `
` elements on their own lines.
{@example 'toh-1/ts-snippets/app.component.snippets.pt1.ts' region='multi-line-strings'}
## Editing Our Hero
We want to be able to edit the hero name in a textbox.
Refactor the hero name `