@@ -73,7 +73,7 @@ After the browser refreshes, the list of heroes appears.
### Style the heroes
-The heroes list should be attractive and should respond visually when users
+The heroes list should be attractive and should respond visually when users
hover over and select a hero from the list.
In the [first tutorial](tutorial/toh-pt0#app-wide-styles), you set the basic styles for the entire application in `styles.css`.
@@ -109,7 +109,7 @@ The `heroes.component.css` styles apply only to the `HeroesComponent` and don't
## Master/Detail
-When the user clicks a hero in the **master** list,
+When the user clicks a hero in the **master** list,
the component should display the selected hero's **details** at the bottom of the page.
In this section, you'll listen for the hero item click event
@@ -144,14 +144,12 @@ to the component's `selectedHero`.
### Update the details template
-The template still refers to the component's old `hero` property which no longer exists.
+The template still refers to the component's old `hero` property which no longer exists.
Rename `hero` to `selectedHero`.
-### Hide empty details with _*ngIf_
-
After the browser refreshes, the application is broken.
Open the browser developer tools and look in the console for an error message like this:
@@ -160,23 +158,25 @@ Open the browser developer tools and look in the console for an error message li
HeroesComponent.html:3 ERROR TypeError: Cannot read property 'name' of undefined
-Now click one of the list items.
-The app seems to be working again.
-The heroes appear in a list and details about the clicked hero appear at the bottom of the page.
-
#### What happened?
When the app starts, the `selectedHero` is `undefined` _by design_.
Binding expressions in the template that refer to properties of `selectedHero` — expressions like `{{selectedHero.name}}` — _must fail_ because there is no selected hero.
-#### The fix
+Now, click one of the list items.
+The app seems to be working again.
+The heroes appear in a list and details about the clicked hero appear at the bottom of the page.
+
+#### The fix - hide empty details with _*ngIf_
+
The component should only display the selected hero details if the `selectedHero` exists.
Wrap the hero detail HTML in a `
`.
Add Angular's `*ngIf` directive to the `
` and set it to `selectedHero`.
+
Don't forget the asterisk (*) in front of `ngIf`. It's a critical part of the syntax.
@@ -212,7 +212,7 @@ If the user clicks "Magneta", that hero should render with a distinctive but sub
That _selected hero_ coloring is the work of the `.selected` CSS class in the [styles you added earlier](#styles).
You just have to apply the `.selected` class to the `
` when the user clicks it.
-The Angular [class binding](guide/template-syntax#class-binding) makes it easy to add and remove a CSS class conditionally.
+The Angular [class binding](guide/template-syntax#class-binding) makes it easy to add and remove a CSS class conditionally.
Just add `[class.some-css-class]="some-condition"` to the element you want to style.
Add the following `[class.selected]` binding to the `` in the `HeroesComponent` template:
@@ -232,7 +232,7 @@ The finished `` looks like this:
## Final code review
-Your app should look like this .
+Your app should look like this .
Here are the code files discussed on this page, including the `HeroesComponent` styles.