From f34cecd3e54250038df29187fb4a3013030ad896 Mon Sep 17 00:00:00 2001 From: Carol Franger Date: Fri, 21 Oct 2016 13:07:41 -0700 Subject: [PATCH 1/5] Initial edits with several questions for Naomi and Ward. --- public/docs/ts/latest/tutorial/toh-pt1.jade | 121 +++++++++++--------- 1 file changed, 64 insertions(+), 57 deletions(-) diff --git a/public/docs/ts/latest/tutorial/toh-pt1.jade b/public/docs/ts/latest/tutorial/toh-pt1.jade index dfc137c3b8..01b08673a9 100644 --- a/public/docs/ts/latest/tutorial/toh-pt1.jade +++ b/public/docs/ts/latest/tutorial/toh-pt1.jade @@ -3,16 +3,14 @@ include ../_util-fns :marked # Once Upon a Time - Every story starts somewhere. Our story starts where the [QuickStart](../quickstart.html) ends. + Run the . - Run the for this part. - - Create a folder called `angular-tour-of-heroes` and follow the [QuickStart](../quickstart.html) steps - which provide the prerequisites, the folder structure, and the core files for our Tour of Heroes. + Create a folder called `angular-tour-of-heroes` and follow the [QuickStart](../quickstart.html) steps, + which provide the prerequisites, folder structure, and core files for the Tour of Heroes. include ../_quickstart_repo :marked - We should have the following structure: + You should have the following structure: .filetree .file angular-tour-of-heroes @@ -32,34 +30,36 @@ include ../_quickstart_repo .file typings.json :marked ## Keep the app transpiling and running - We want to start the TypeScript compiler, have it watch for changes, and start our server. We'll do this by typing + Type the following command: code-example(language="bash"). npm start :marked 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. + and keeps the app running while you build the Tour of Heroes. .l-main-section :marked - ## Show our Hero - We want to display Hero data in our app - - Let's add two properties to our `AppComponent`, a `title` property for the application name and a `hero` property - for a hero named "Windstorm". + ## Show Your Hero + To display Hero data in the app, + add two properties to the `AppComponent`: a `title` property for the application name and a `hero` property + + for a hero named "Windstorm." +makeExample('toh-1/ts-snippets/app.component.snippets.pt1.ts', 'app-component-1', 'app.component.ts (AppComponent class)')(format=".") :marked - Now we update the template in the `@Component` decoration with data bindings to these new properties. + Now update the template in the `@Component` decoration with data bindings to these new properties. +makeExample('toh-1/ts-snippets/app.component.snippets.pt1.ts', 'show-hero') :marked - The browser should refresh and display our title and hero. + The browser should refresh and display the title and hero name. + - The double curly braces tell our app to read the `title` and `hero` properties from the component and render them. + The double curly braces instruct the app to read the `title` and `hero` properties from the component and render them. This is the "interpolation" form of one-way data binding. .l-sub-section :marked @@ -67,45 +67,46 @@ code-example(language="bash"). :marked ### Hero object - At the moment, our hero is just a name. Our hero needs more properties. + 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. + For now, add these properties near the top of the `app.component.ts` file, just below the import statement. +makeExample('toh-1/ts/app/app.component.ts', 'hero-class-1', 'app.component.ts (Hero class)')(format=".") :marked - 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". + Now in your `Hero` class, refactor the component’s `hero` property to be of type `Hero`, + + then initialize it with an id of `1` and the name "Windstorm." +makeExample('toh-1/ts/app/app.component.ts', 'hero-property-1', 'app.component.ts (hero property)')(format=".") :marked - 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. + Because you changed the hero from a string to an object, + update the binding in the template to refer to the hero’s `name` property. +makeExample('toh-1/ts-snippets/app.component.snippets.pt1.ts', 'show-hero-2') :marked - The browser refreshes and continues to display our hero’s name. + The browser refreshes and continues to display the 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`. + + Displaying a name is good, but we want to see all of the hero’s properties. + Add a `
` for the hero’s `id` property and another `
` for the hero’s `name`. +makeExample('toh-1/ts-snippets/app.component.snippets.pt1.ts', 'show-hero-properties') :marked - 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. + Uh oh, the template string is getting long. Let's clean up the code to avoid making typos 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. + Let’s use the template strings feature + in ES2015 and TypeScript. - Change the quotes around the template to back-ticks and + Change the quotes around the template to backticks and put the `

`, `

` and `
` elements on their own lines. +makeExample('toh-1/ts-snippets/app.component.snippets.pt1.ts', 'multi-line-strings', 'app.component.ts (AppComponent\'s template)') @@ -119,33 +120,33 @@ code-example(language="bash"). Here we use them in a limited way to spread the template over multiple lines. Everything between the back-ticks at the beginning and end of the template is part of a single template string. + .l-main-section :marked - ## Editing Our Hero + ## Editing the Hero Name We want to be able to edit the hero name in a textbox. - Refactor the hero name `