` with an `*ngFor` to display each of the cart items with its name and price.
-
- The resulting `CartComponent` template is as follows:
+1. Update the cart template with a header, and use a `
` with an `*ngFor` to display each of the cart items with its name and price.
+ The resulting `CartComponent` template is as follows.
-1. Test your cart component.
+1. Verify that your cart works as expected:
- 1. Click on "My Store" to go to the product list view.
- 1. Click on a product name to display its details.
- 1. Click "Buy" to add the product to the cart.
- 1. Click "Checkout" to see the cart.
- 1. To add another product, click "My Store" to return to the product list.
-
- Repeat to add more items to the cart.
+ * Click **My Store**
+ * Click on a product name to display its details.
+ * Click **Buy** to add the product to the cart.
+ * Click **Checkout** to see the cart.
-
-
-
-StackBlitz tip: Any time the preview refreshes, the cart is cleared. If you make changes to the app, the page refreshes, so you'll need to buy products again to populate the cart.
-
-
-
-
-
For more information about services, see [Introduction to Services and Dependency Injection](guide/architecture-services "Concepts > Intro to Services and DI").
-
-
-
## Retrieve shipping prices
-
Servers often return data in the form of a stream.
Streams are useful because they make it easy to transform the returned data and make modifications to the way you request that data.
-The Angular HTTP client, `HttpClient`, is a built-in way to fetch data from external APIs and provide them to your app as a stream.
+Angular `HttpClient` is a built-in way to fetch data from external APIs and provide them to your application as a stream.
-This section shows you how to use the HTTP client to retrieve shipping prices from an external file.
-
-### Predefined shipping data
+This section shows you how to use `HttpClient` to retrieve shipping prices from an external file.
The application that StackBlitz generates for this guide comes with predefined shipping data in `assets/shipping.json`.
Use this data to add shipping prices for items in the cart.
@@ -249,111 +185,98 @@ Use this data to add shipping prices for items in the cart.
+### Configure `AppModule` to use `HttpClient`
-### Use `HttpClient` in the `AppModule`
+To use Angular's `HttpClient`, you must configure your application to use `HttpClientModule`.
-Before you can use Angular's HTTP client, you must configure your app to use `HttpClientModule`.
+Angular's `HttpClientModule` registers the providers your application needs to use the `HttpClient` service throughout your application.
-Angular's `HttpClientModule` registers the providers your app needs to use a single instance of the `HttpClient` service throughout your app.
-
-1. Open `app.module.ts`.
-
- This file contains imports and functionality that is available to the entire app.
-
-1. Import `HttpClientModule` from the `@angular/common/http` package at the top of the file with the other imports. As there are a number of other imports, this code snippet omits them for brevity. Be sure to leave the existing imports in place.
+1. In `app.module.ts`, import `HttpClientModule` from the `@angular/common/http` package at the top of the file with the other imports.
+ As there are a number of other imports, this code snippet omits them for brevity.
+ Be sure to leave the existing imports in place.
-1. Add `HttpClientModule` to the `AppModule` `@NgModule()` `imports` array to register Angular's `HttpClient` providers globally.
+1. To register Angular's `HttpClient` providers globally, add `HttpClientModule` to the `AppModule` `@NgModule()` `imports` array.
-### Use `HttpClient` in the cart service
+### Configure `CartService` to use `HttpClient`
-Now that the `AppModule` imports the `HttpClientModule`, the next step is to inject the `HttpClient` service into your service so your app can fetch data and interact with external APIs and resources.
+The next step is to inject the `HttpClient` service into your service so your application can fetch data and interact with external APIs and resources.
-
-1. Open `cart.service.ts`.
-
-1. Import `HttpClient` from the `@angular/common/http` package.
+1. In `cart.service.ts`, import `HttpClient` from the `@angular/common/http` package.
-1. Inject `HttpClient` into the `CartService` constructor:
+1. Inject `HttpClient` into the `CartService` `constructor()`.
+### Configure `CartService` to get shipping prices
-### Define the `get()` method
+To get shipping data, from `shipping.json`, You can use the `HttpClient` `get()` method.
-Multiple components can leverage the same service.
-Later in this tutorial, the shipping component uses the cart service to retrieve shipping data via HTTP from the `shipping.json` file.
-First, define a `get()` method.
-
-1. Continue working in `cart.service.ts`.
-
-1. Below the `clearCart()` method, define a new `getShippingPrices()` method that uses the `HttpClient` `get()` method to retrieve the shipping data.
+1. In `cart.service.ts`, below the `clearCart()` method, define a new `getShippingPrices()` method that uses the `HttpClient` `get()` method.
-
-
-
For more information about Angular's `HttpClient`, see the [Client-Server Interaction](guide/http "Server interaction through HTTP") guide.
-
+## Create a shipping component
-## Define the shipping view
+Now that you've configured your application to retrieve shipping data, you can create a place to render that data.
-Now that your app can retrieve shipping data, create a shipping component and template.
-
-1. Generate a new component named `shipping`.
-
- Reminder: In the file list, right-click the `app` folder, choose `Angular Generator` and `Component`.
+1. Generate a new component named `shipping` by right-clicking the `app` folder, choosing **Angular Generator**, and selecting **Component**.
-1. In `app.module.ts`, add a route for shipping. Specify a `path` of `shipping` and a component of `ShippingComponent`.
+1. In `app.module.ts`, add a route for shipping.
+ Specify a `path` of `shipping` and a component of `ShippingComponent`.
- There's no link to the new shipping component yet, but you can see its template in the preview pane by entering the URL its route specifies. The URL has the pattern: `https://getting-started.stackblitz.io/shipping` where the `getting-started.stackblitz.io` part may be different for your StackBlitz project.
+ There's no link to the new shipping component yet, but you can see its template in the preview pane by entering the URL its route specifies.
+ The URL has the pattern: `https://getting-started.stackblitz.io/shipping` where the `getting-started.stackblitz.io` part may be different for your StackBlitz project.
-1. Modify the shipping component so that it uses the cart service to retrieve shipping data via HTTP from the `shipping.json` file.
+### Configuring the `ShippingComponent` to use `CartService`
- 1. Import the cart service.
+This section guides you through modifying the `ShippingComponent` to retrieve shipping data via HTTP from the `shipping.json` file.
-
+1. In `shipping.component.ts`, import `CartService`.
- 1. Define a `shippingCosts` property.
+
-
+1. Define a `shippingCosts` property.
- 1. Inject the cart service in the `ShippingComponent` constructor:
+
-
+1. Inject the cart service in the `ShippingComponent` `constructor()`.
- 1. Set the `shippingCosts` property using the `getShippingPrices()` method from the cart service.
+
-
+1. Set the `shippingCosts` property using the `getShippingPrices()` method from the `CartService`.
-1. Update the shipping component's template to display the shipping types and prices using the `async` pipe:
+
+
+1. Update the `ShippingComponent` template to display the shipping types and prices using the `async` pipe.
- The `async` pipe returns the latest value from a stream of data and continues to do so for the life of a given component. When Angular destroys that component, the `async` pipe automatically stops. For detailed information about the `async` pipe, see the [AsyncPipe API documentation](/api/common/AsyncPipe).
+ The `async` pipe returns the latest value from a stream of data and continues to do so for the life of a given component.
+ When Angular destroys that component, the `async` pipe automatically stops.
+ For detailed information about the `async` pipe, see the [AsyncPipe API documentation](/api/common/AsyncPipe).
-1. Add a link from the cart view to the shipping view:
+1. Add a link from the `CartComponent` view to the `ShippingComponent` view.
-1. Test your shipping prices feature:
-
- Click the "Checkout" button to see the updated cart. Remember that changing the app causes the preview to refresh, which empties the cart.
+1. Click the **Checkout** button to see the updated cart.
+ Remember that changing the application causes the preview to refresh, which empties the cart.

@@ -365,11 +288,13 @@ Now that your app can retrieve shipping data, create a shipping component and t
+
-## Next steps
+## What's next
-Congratulations! You have an online store application with a product catalog and shopping cart. You can also look up and display shipping prices.
+You now have a store application with a product catalog, a shopping cart, and you can look up shipping prices.
-To continue exploring Angular, choose either of the following options:
-* [Continue to the "Forms" section](start/start-forms "Try it: Forms for User Input") to finish the app by adding the shopping cart view and a checkout form.
-* [Skip ahead to the "Deployment" section](start/start-deployment "Try it: Deployment") to move to local development, or deploy your app to Firebase or your own server.
+To continue exploring Angular:
+
+* Continue to [Forms for User Input](start/start-forms "Forms for User Input") to finish the application by adding the shopping cart view and a checkout form.
+* Skip ahead to [Deployment](start/start-deployment "Deployment") to move to local development, or deploy your application to Firebase or your own server.