From 3805172f9c05c5f09e1bcd1df1b9846823f75bb9 Mon Sep 17 00:00:00 2001 From: Kapunahele Wong Date: Fri, 20 Sep 2019 16:22:58 -0400 Subject: [PATCH] docs: edit copy of getting started step 3 (#32820) PR Close #32820 --- .../getting-started/src/app/app.module.ts | 3 +- aio/content/start/data.md | 202 ++++++++---------- 2 files changed, 92 insertions(+), 113 deletions(-) diff --git a/aio/content/examples/getting-started/src/app/app.module.ts b/aio/content/examples/getting-started/src/app/app.module.ts index fd49de191f..36a43eefc2 100644 --- a/aio/content/examples/getting-started/src/app/app.module.ts +++ b/aio/content/examples/getting-started/src/app/app.module.ts @@ -1,8 +1,8 @@ // #docplaster -// #docregion http-client-module-import, http-client-module import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { RouterModule } from '@angular/router'; +// #docregion http-client-module-import import { HttpClientModule } from '@angular/common/http'; // #enddocregion http-client-module-import import { ReactiveFormsModule } from '@angular/forms'; @@ -12,7 +12,6 @@ import { TopBarComponent } from './top-bar/top-bar.component'; import { ProductListComponent } from './product-list/product-list.component'; import { ProductAlertsComponent } from './product-alerts/product-alerts.component'; import { ProductDetailsComponent } from './product-details/product-details.component'; -// #enddocregion http-client-module import { CartComponent } from './cart/cart.component'; import { ShippingComponent } from './shipping/shipping.component'; diff --git a/aio/content/start/data.md b/aio/content/start/data.md index 1df3b65016..b224d64a94 100644 --- a/aio/content/start/data.md +++ b/aio/content/start/data.md @@ -1,31 +1,36 @@ # Managing Data At the end of [Routing](start/routing "Getting Started: Routing"), the online store application has a product catalog with two views: a product list and product details. -Users can click on a product name from the list to see details in a new view, with a distinct URL (route). +Users can click on a product name from the list to see details in a new view, with a distinct URL, or route. -In this section, you'll create the shopping cart. You'll: -* Update the product details page to include a "Buy" button, which adds the current product to a list of products managed by a cart service. -* Add a cart component, which displays the items you added to your cart. +This page guides you through creating the shopping cart in three phases: +* Update the product details page to include a "Buy" button, which adds the current product to a list of products that a cart service manages. +* Add a cart component, which displays the items in the cart. * Add a shipping component, which retrieves shipping prices for the items in the cart by using Angular's `HttpClient` to retrieve shipping data from a `.json` file. {@a services} ## Services -Services are an integral part of Angular applications. In Angular, a service is an instance of a class that can be made available to any part of your application using Angular's [dependency injection system](guide/glossary#dependency-injection-di "dependency injection definition"). +Services are an integral part of Angular applications. In Angular, a service is an instance of a class that you can make available to any part of your application using Angular's [dependency injection system](guide/glossary#dependency-injection-di "dependency injection definition"). Services are the place where you share data between parts of your application. For the online store, the cart service is where you store your cart data and methods. {@a create-cart-service} ## Create the shopping cart service -Up to this point, users can view product information, and simulate sharing and being notified about product changes. They cannot, however, buy products. +Up to this point, users can view product information, and +simulate sharing and being notified about product changes. +They cannot, however, buy products. -In this section, you'll add a "Buy" button to the product details page. -You'll also set up a cart service to store information about products in the cart. +In this section, you add a "Buy" button to the product +details page and set up a cart service to store information +about products in the cart.
-Later, in the [Forms](start/forms "Getting Started: Forms") part of this tutorial, this cart service also will be accessed from the page where the user checks out. +Later, the [Forms](start/forms "Getting Started: Forms") part of +this tutorial guides you through accessing this cart service +from the page where the user checks out.
@@ -38,47 +43,40 @@ Later, in the [Forms](start/forms "Getting Started: Forms") part of this tutoria - 1. If the generated `@Injectable()` decorator does not include the `{ providedIn: 'root' }` statement, then insert it as shown above. + 1. StackBlitz might generate the `@Injectable()` decorator without the `{ providedIn: 'root' }` statement as above. Instead, the generator provides the cart service in `app.module.ts` by default. For the purposes + of this tutorial, either way works. The `@Injectable()` `{ providedIn: 'root' }` syntax allows [tree shaking](/guide/dependency-injection-providers#tree-shakable-providers), which is beyond the scope of this guide. -1. In the `CartService` class, define an `items` property to store the list (array) of the current products in the cart. +1. In the `CartService` class, define an `items` property to store the array of the current products in the cart. - + 1. Define methods to add items to the cart, return cart items, and clear the cart items: - + - - - {@a product-details-use-cart-service} ### Use the cart service -In this section, you'll update the product details component to use the cart service. -You'll add a "Buy" button to the product details view. -When the "Buy" button is clicked, you'll use the cart service to add the current product to the cart. +This section walks you through using the cart service to add a product to the cart with a "Buy" button. 1. Open `product-details.component.ts`. -1. Set up the component to be able to use the cart service. +1. Configure the component to use the cart service. 1. Import the cart service. - 1. Inject the cart service. + 1. Inject the cart service by adding it to the `constructor()`. - + - 1. To see the new cart component, click the "Checkout" button. You can see the "cart works!" default text, and the URL has the pattern `https://getting-started.stackblitz.io/cart`, where `getting-started.stackblitz.io` may be different for your StackBlitz project. - (Note: The "Checkout" button that we provided in the top-bar component was already configured with a `routerLink` for `/cart`.) +
+ + The starter code for the "Checkout" button already includes a `routerLink` for `/cart` the top-bar component. + +