From 1c4fb90857265a3287c995e6ad4f10c2bee73a69 Mon Sep 17 00:00:00 2001 From: SkyZeroZx <73321943+SkyZeroZx@users.noreply.github.com> Date: Wed, 12 Nov 2025 14:50:23 -0500 Subject: [PATCH] docs: update tutorials with self-closing tags, standalone router directives, and fix syntax highlighting (cherry picked from commit 4544135b1e335084c116b6669b43b5b67930e3fa) --- .../first-app/steps/01-hello-world/README.md | 12 +- .../first-app/steps/02-Home/README.md | 14 +- .../steps/03-HousingLocation/README.md | 14 +- .../first-app/steps/04-interfaces/README.md | 10 +- .../steps/04-interfaces/src/app/home/home.ts | 2 +- .../first-app/steps/05-inputs/README.md | 2 +- .../steps/05-inputs/src/app/home/home.ts | 2 +- .../steps/06-property-binding/README.md | 2 +- .../07-dynamic-template-values/README.md | 2 +- .../src/app/home/home.ts | 2 +- .../first-app/steps/08-ngFor/README.md | 4 +- .../steps/08-ngFor/src/app/home/home.ts | 2 +- .../first-app/steps/09-services/README.md | 6 +- .../steps/09-services/src/app/home/home.ts | 2 +- .../first-app/steps/10-routing/README.md | 10 +- .../first-app/steps/10-routing/src/app/app.ts | 2 +- .../steps/10-routing/src/app/home/home.ts | 2 +- .../first-app/steps/11-details-page/README.md | 24 +- .../steps/11-details-page/src/app/app.ts | 6 +- .../11-details-page/src/app/home/home.ts | 2 +- .../app/housing-location/housing-location.ts | 4 +- .../first-app/steps/12-forms/README.md | 2 +- .../first-app/steps/12-forms/src/app/app.ts | 2 +- .../steps/12-forms/src/app/home/home.ts | 2 +- .../app/housing-location/housing-location.ts | 4 +- .../first-app/steps/13-search/README.md | 4 +- .../steps/13-search/src/app/home/home.ts | 2 +- .../app/housing-location/housing-location.ts | 4 +- .../first-app/steps/14-http/README.md | 222 +++++++++--------- .../steps/14-http/src-final/app/app.ts | 2 +- .../steps/14-http/src-final/app/home/home.ts | 2 +- .../app/housing-location/housing-location.ts | 4 +- .../first-app/steps/14-http/src/app/app.ts | 2 +- .../steps/14-http/src/app/home/home.ts | 2 +- .../app/housing-location/housing-location.ts | 4 +- .../13-define-a-route/answer/src/app/app.ts | 2 +- .../steps/13-define-a-route/src/app/app.ts | 2 +- .../playground/3-minigame/src/game.html | 6 +- .../playground/3-minigame/src/main.ts | 38 +-- .../README.md | 6 +- .../README.md | 2 +- .../README.md | 2 +- .../README.md | 2 +- .../README.md | 2 +- .../7-using-signals-with-services/README.md | 2 +- .../answer/src/app/app.ts | 2 +- .../8-using-signals-with-directives/README.md | 2 +- 47 files changed, 228 insertions(+), 224 deletions(-) diff --git a/adev/src/content/tutorials/first-app/steps/01-hello-world/README.md b/adev/src/content/tutorials/first-app/steps/01-hello-world/README.md index 170c0ede73e..5052679e89f 100644 --- a/adev/src/content/tutorials/first-app/steps/01-hello-world/README.md +++ b/adev/src/content/tutorials/first-app/steps/01-hello-world/README.md @@ -28,15 +28,15 @@ In the **Terminal** pane of your IDE: 1. In your project directory, navigate to the `first-app` directory. 1. Run this command to install the dependencies needed to run the app. - -npm install - + ```shell + npm install + ``` 1. Run this command to build and serve the default app. - + ```shell ng serve - + ``` The app should build without errors. @@ -96,7 +96,7 @@ In your IDE: 1. Next, open `first-app/src/app/app.ts`. 1. In `app.ts`, in the `@Component` definition, replace the `template` line with this code to change the text in the app component. - + 1. In `app.ts`, in the `App` class definition, replace the `title` line with this code to change the component title. diff --git a/adev/src/content/tutorials/first-app/steps/02-Home/README.md b/adev/src/content/tutorials/first-app/steps/02-Home/README.md index 32199e4092e..9af6c5e5e07 100644 --- a/adev/src/content/tutorials/first-app/steps/02-Home/README.md +++ b/adev/src/content/tutorials/first-app/steps/02-Home/README.md @@ -37,17 +37,17 @@ In the **Terminal** pane of your IDE: 1. In your project directory, navigate to the `first-app` directory. 1. Run this command to create a new `Home` - -ng generate component home - + ```shell + ng generate component home + ``` 1. Run this command to build and serve your app. NOTE: This step is only for your local environment! - + ```shell ng serve - + ``` 1. Open a browser and navigate to `http://localhost:4200` to find the application. @@ -74,7 +74,7 @@ In the **Edit** pane of your IDE: 1. In `app.ts`, in `@Component`, update the `template` property to include the following HTML code. - + 1. Save your changes to `app.ts`. 1. If `ng serve` is running, the app should update. @@ -100,7 +100,7 @@ In the **Edit** pane of your IDE: 1. In the `first-app` directory, open `home.ts` in the editor. 1. In `home.ts`, in `@Component`, update the `template` property with this code. - + 1. Next, open `home.css` in the editor and update the content with these styles. diff --git a/adev/src/content/tutorials/first-app/steps/03-HousingLocation/README.md b/adev/src/content/tutorials/first-app/steps/03-HousingLocation/README.md index 0d7877c1c5e..d3c3ba6018c 100644 --- a/adev/src/content/tutorials/first-app/steps/03-HousingLocation/README.md +++ b/adev/src/content/tutorials/first-app/steps/03-HousingLocation/README.md @@ -19,15 +19,15 @@ In the **Terminal** pane of your IDE: 1. Run this command to create a new `HousingLocation` - -ng generate component housingLocation - + ```shell + ng generate component housingLocation + ``` 1. Run this command to build and serve your app. - + ```shell ng serve - + ``` NOTE: This step is only for your local environment! @@ -51,11 +51,11 @@ In the **Edit** pane of your IDE: 1. Next update the `imports` property of the `@Component` metadata by adding `HousingLocation` to the array. - + 1. Now the component is ready for use in the template for the `Home`. Update the `template` property of the `@Component` metadata to include a reference to the `` tag. - + diff --git a/adev/src/content/tutorials/first-app/steps/04-interfaces/README.md b/adev/src/content/tutorials/first-app/steps/04-interfaces/README.md index de4a3867656..5d9f3965813 100644 --- a/adev/src/content/tutorials/first-app/steps/04-interfaces/README.md +++ b/adev/src/content/tutorials/first-app/steps/04-interfaces/README.md @@ -29,11 +29,11 @@ In the **Terminal** pane of your IDE: 1. In your project directory, navigate to the `first-app` directory. 1. In the `first-app` directory, run this command to create the new interface. - + ```shell ng generate interface housinglocation - + ``` 1. Run `ng serve` to build the app and serve it to `http://localhost:4200`. 1. In a browser, open `http://localhost:4200` to see your app. @@ -66,15 +66,15 @@ There are a few more lessons to complete before that happens. 1. In the **Edit** pane of your IDE, open `src/app/home/home.ts`. 1. In `src/app/home/home.ts`, add this import statement after the existing `import` statements so that `Home` can use the new interface. - + 1. In `src/app/home/home.ts`, replace the empty `export class Home {}` definition with this code to create a single instance of the new interface in the component. - + 1. Confirm that your `home.ts` file matches this example. - + By adding the `housingLocation` property of type `HousingLocation` to the `Home` class, we're able to confirm that the data matches the description of the interface. If the data didn't satisfy the description of the interface, the IDE has enough information to give us helpful errors. diff --git a/adev/src/content/tutorials/first-app/steps/04-interfaces/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/04-interfaces/src/app/home/home.ts index b73b5bed172..93f338e1e2a 100644 --- a/adev/src/content/tutorials/first-app/steps/04-interfaces/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/04-interfaces/src/app/home/home.ts @@ -12,7 +12,7 @@ import {HousingLocation} from '../housing-location/housing-location';
- +
`, styleUrls: ['./home.css'], diff --git a/adev/src/content/tutorials/first-app/steps/05-inputs/README.md b/adev/src/content/tutorials/first-app/steps/05-inputs/README.md index e15c0e15fe1..df1d40976aa 100644 --- a/adev/src/content/tutorials/first-app/steps/05-inputs/README.md +++ b/adev/src/content/tutorials/first-app/steps/05-inputs/README.md @@ -39,7 +39,7 @@ You have to invoke the `required` method on `input` to indicate that the parent Send the `housingLocation` value from the `Home` component to the `housingLocation` property of the HousingLocation component. - + diff --git a/adev/src/content/tutorials/first-app/steps/05-inputs/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/05-inputs/src/app/home/home.ts index f01102134e6..0374da82ba5 100644 --- a/adev/src/content/tutorials/first-app/steps/05-inputs/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/05-inputs/src/app/home/home.ts @@ -13,7 +13,7 @@ import {HousingLocationInfo} from '../housinglocation';
- +
`, styleUrls: ['./home.css'], diff --git a/adev/src/content/tutorials/first-app/steps/06-property-binding/README.md b/adev/src/content/tutorials/first-app/steps/06-property-binding/README.md index 7c1f2888321..0bf9b0a5e4e 100644 --- a/adev/src/content/tutorials/first-app/steps/06-property-binding/README.md +++ b/adev/src/content/tutorials/first-app/steps/06-property-binding/README.md @@ -26,7 +26,7 @@ In the code editor: 1. Navigate to `src/app/home/home.ts` 1. In the template property of the `@Component` decorator, update the code to match the code below: - + When adding a property binding to a component tag, we use the `[attribute] = "value"` syntax to notify Angular that the assigned value should be treated as a property from the component class and not a string value. diff --git a/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/README.md b/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/README.md index 0017d56da58..a1654ec7b18 100644 --- a/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/README.md +++ b/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/README.md @@ -27,7 +27,7 @@ In the code editor: 1. Navigate to `src/app/housing-location/housing-location.ts` 1. In the template property of the `@Component` decorator, replace the existing HTML markup with the following code: - + In this updated template code you have used property binding to bind the `housingLocation.photo` to the `src` attribute. The `alt` attribute uses interpolation to give more context to the alt text of the image. diff --git a/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/app/home/home.ts index 9b165a360da..e2f8657683c 100644 --- a/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/app/home/home.ts @@ -13,7 +13,7 @@ import {HousingLocationInfo} from '../housinglocation';
- +
`, styleUrls: ['./home.css'], diff --git a/adev/src/content/tutorials/first-app/steps/08-ngFor/README.md b/adev/src/content/tutorials/first-app/steps/08-ngFor/README.md index 08b2104905c..0628c9c480e 100644 --- a/adev/src/content/tutorials/first-app/steps/08-ngFor/README.md +++ b/adev/src/content/tutorials/first-app/steps/08-ngFor/README.md @@ -27,7 +27,7 @@ In the `Home` there is only a single housing location. In this step, you will ad 1. In `src/app/home/home.ts`, remove the `housingLocation` property from the `Home` class. 1. Update the `Home` class to have a property called `housingLocationList`. Update your code to match the following code: - + IMPORTANT: Do not remove the `@Component` decorator, you will update that code in an upcoming step. @@ -37,7 +37,7 @@ In the `Home` there is only a single housing location. In this step, you will ad Now the app has a dataset that you can use to display the entries in the browser using the `@for` block. 1. Update the `` tag in the template code to this: - + Note, in the code `[housingLocation] = "housingLocation"` the `housingLocation` value now refers to the variable used in the `@for` block. Before this change, it referred to the property on the `Home` class. diff --git a/adev/src/content/tutorials/first-app/steps/08-ngFor/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/08-ngFor/src/app/home/home.ts index 9b165a360da..e2f8657683c 100644 --- a/adev/src/content/tutorials/first-app/steps/08-ngFor/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/08-ngFor/src/app/home/home.ts @@ -13,7 +13,7 @@ import {HousingLocationInfo} from '../housinglocation';
- +
`, styleUrls: ['./home.css'], diff --git a/adev/src/content/tutorials/first-app/steps/09-services/README.md b/adev/src/content/tutorials/first-app/steps/09-services/README.md index 67866999680..591f3fcd62b 100644 --- a/adev/src/content/tutorials/first-app/steps/09-services/README.md +++ b/adev/src/content/tutorials/first-app/steps/09-services/README.md @@ -77,17 +77,17 @@ In the **Edit** pane of your IDE, in `src/app/home/home.ts`: 1. At the top of `src/app/home/home.ts`, add the `inject` to the items imported from `@angular/core`. This will import the `inject` function into the `Home` class. - + 1. Add a new file level import for the `HousingService`: - + 1. From `Home`, delete the `housingLocationList` array entries and assign `housingLocationList` the value of empty array (`[]`). In a few steps you will update the code to pull the data from the `HousingService`. 1. In `Home`, add the following code to inject the new service and initialize the data for the app. The `constructor` is the first function that runs when this component is created. The code in the `constructor` will assign the `housingLocationList` the value returned from the call to `getAllHousingLocations`. - + 1. Save the changes to `src/app/home/home.ts` and confirm your app builds without error. Correct any errors before you continue to the next step. diff --git a/adev/src/content/tutorials/first-app/steps/09-services/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/09-services/src/app/home/home.ts index b4875e76d8e..c6cb4b0b5c0 100644 --- a/adev/src/content/tutorials/first-app/steps/09-services/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/09-services/src/app/home/home.ts @@ -14,7 +14,7 @@ import {HousingLocationInfo} from '../housinglocation';
@for(housingLocation of housingLocationList; track $index) { - + }
`, diff --git a/adev/src/content/tutorials/first-app/steps/10-routing/README.md b/adev/src/content/tutorials/first-app/steps/10-routing/README.md index 636d99ba5f2..c9ae7935a9c 100644 --- a/adev/src/content/tutorials/first-app/steps/10-routing/README.md +++ b/adev/src/content/tutorials/first-app/steps/10-routing/README.md @@ -43,15 +43,15 @@ In this lesson, you will enable routing in your application to navigate to the d 1. In `src/app/app.ts`, update the component to use routing: - 1. Add a file level import for `RoutingModule`: + 1. Add file level imports for the router directives `RouterOutlet` and `RouterLink`: - - 1. Add `RouterModule` to the `@Component` metadata imports + + 1. Add `RouterOutlet` and `RouterLink` to the `@Component` metadata imports - + 1. In the `template` property, replace the `` tag with the `` directive and add a link back to the home page. Your code should match this code: - + diff --git a/adev/src/content/tutorials/first-app/steps/10-routing/src/app/app.ts b/adev/src/content/tutorials/first-app/steps/10-routing/src/app/app.ts index b67e16f7f68..24174f4e013 100644 --- a/adev/src/content/tutorials/first-app/steps/10-routing/src/app/app.ts +++ b/adev/src/content/tutorials/first-app/steps/10-routing/src/app/app.ts @@ -10,7 +10,7 @@ import {Home} from './home/home';
- +
`, diff --git a/adev/src/content/tutorials/first-app/steps/10-routing/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/10-routing/src/app/home/home.ts index 5d267690e45..4ccd865f60a 100644 --- a/adev/src/content/tutorials/first-app/steps/10-routing/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/10-routing/src/app/home/home.ts @@ -14,7 +14,7 @@ import {HousingService} from '../housing.service';
@for(housingLocation of housingLocationList; track $index) { - + }
`, diff --git a/adev/src/content/tutorials/first-app/steps/11-details-page/README.md b/adev/src/content/tutorials/first-app/steps/11-details-page/README.md index e699878fa03..8b92116fa9d 100644 --- a/adev/src/content/tutorials/first-app/steps/11-details-page/README.md +++ b/adev/src/content/tutorials/first-app/steps/11-details-page/README.md @@ -21,15 +21,15 @@ Route parameters enable you to include dynamic information as a part of your rou In lesson 10, you added a second route to `src/app/routes.ts` which includes a special segment that identifies the route parameter, `id`: - +``` 'details/:id' - +``` In this case, `:id` is dynamic and will change based on how the route is requested by the code. 1. In `src/app/housing-location/housing-location.ts`, add an anchor tag to the `section` element and include the `routerLink` directive: - + The `routerLink` directive enables Angular's router to create dynamic links in the application. The value assigned to the `routerLink` is an array with two entries: the static portion of the path and the dynamic data. @@ -50,13 +50,13 @@ In this step, you will get the route parameter in the `Details`. Currently, the 1. Update the `template` property of the `@Component` decorator to display the value `housingLocationId`: - - template: `

details works! {{ housingLocationId }}

`, -
+ ```angular-ts + template: `

details works! {{ housingLocationId }}

`, + ``` 1. Update the body of the `Details` class with the following code: - + ```ts export class Details { route: ActivatedRoute = inject(ActivatedRoute); housingLocationId = -1; @@ -64,7 +64,7 @@ In this step, you will get the route parameter in the `Details`. Currently, the this.housingLocationId = Number(this.route.snapshot.params['id']); } } - + ``` This code gives the `Details` access to the `ActivatedRoute` router feature that enables you to have access to the data about the current route. In the `constructor`, the code converts the `id` parameter acquired from the route from a string to a number. @@ -80,13 +80,13 @@ To access the data you will add a call to the `HousingService`. 1. Update the template code to match the following code: - + Notice that the `housingLocation` properties are being accessed with the optional chaining operator `?`. This ensures that if the `housingLocation` value is null or undefined the application doesn't crash. 1. Update the body of the `Details` class to match the following code: - + Now the component has the code to display the correct information based on the selected housing location. The `constructor` now includes a call to the `HousingService` to pass the route parameter as an argument to the `getHousingLocationById` service function. @@ -97,7 +97,7 @@ To access the data you will add a call to the `HousingService`. and save your changes 1. In `Details` use the just created `details.css` file as the source for the styles: - + 1. In the browser refresh the page and confirm that when you click on the "Learn More" link for a given housing location the details page displays the correct information based on the data for that selected item. @@ -110,7 +110,7 @@ In a previous lesson you updated the `App` template to include a `routerLink`. A 1. Confirm that your code matches the following: - + Your code should already be up-to-date but confirm to be sure. diff --git a/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/app.ts b/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/app.ts index afbfa8697cc..ff01a9c16e0 100644 --- a/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/app.ts +++ b/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/app.ts @@ -1,9 +1,9 @@ import {Component} from '@angular/core'; import {Home} from './home/home'; -import {RouterModule} from '@angular/router'; +import {RouterLink, RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', - imports: [Home, RouterModule], + imports: [Home, RouterOutlet, RouterLink], template: `
@@ -12,7 +12,7 @@ import {RouterModule} from '@angular/router';
- +
`, diff --git a/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/home/home.ts index d8375a3d475..43a2b0002cf 100644 --- a/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/home/home.ts @@ -15,7 +15,7 @@ import {HousingService} from '../housing.service';
@for(housingLocation of housingLocationList; track $index) { - + }
`, diff --git a/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/housing-location/housing-location.ts b/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/housing-location/housing-location.ts index 961799b8da8..84de14b417f 100644 --- a/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/housing-location/housing-location.ts +++ b/adev/src/content/tutorials/first-app/steps/11-details-page/src/app/housing-location/housing-location.ts @@ -1,10 +1,10 @@ import {Component, input} from '@angular/core'; import {HousingLocationInfo} from '../housinglocation'; -import {RouterModule} from '@angular/router'; +import {RouterLink} from '@angular/router'; @Component({ selector: 'app-housing-location', - imports: [RouterModule], + imports: [RouterLink], template: `
+ The template now includes an event handler `(submit)="submitApplication()"`. Angular uses parentheses syntax around the event name to define events in the template code. The code on the right hand side of the equals sign is the code that should be executed when this event is triggered. You can bind to browser events and custom events. diff --git a/adev/src/content/tutorials/first-app/steps/12-forms/src/app/app.ts b/adev/src/content/tutorials/first-app/steps/12-forms/src/app/app.ts index c9be1236e28..fa549e7c45a 100644 --- a/adev/src/content/tutorials/first-app/steps/12-forms/src/app/app.ts +++ b/adev/src/content/tutorials/first-app/steps/12-forms/src/app/app.ts @@ -13,7 +13,7 @@ import {RouterLink, RouterOutlet} from '@angular/router';
- +
`, diff --git a/adev/src/content/tutorials/first-app/steps/12-forms/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/12-forms/src/app/home/home.ts index d8375a3d475..43a2b0002cf 100644 --- a/adev/src/content/tutorials/first-app/steps/12-forms/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/12-forms/src/app/home/home.ts @@ -15,7 +15,7 @@ import {HousingService} from '../housing.service';
@for(housingLocation of housingLocationList; track $index) { - + }
`, diff --git a/adev/src/content/tutorials/first-app/steps/12-forms/src/app/housing-location/housing-location.ts b/adev/src/content/tutorials/first-app/steps/12-forms/src/app/housing-location/housing-location.ts index 13568524465..09605664854 100644 --- a/adev/src/content/tutorials/first-app/steps/12-forms/src/app/housing-location/housing-location.ts +++ b/adev/src/content/tutorials/first-app/steps/12-forms/src/app/housing-location/housing-location.ts @@ -1,10 +1,10 @@ import {Component, input} from '@angular/core'; import {HousingLocationInfo} from '../housinglocation'; -import {RouterModule} from '@angular/router'; +import {RouterLink} from '@angular/router'; @Component({ selector: 'app-housing-location', - imports: [RouterModule], + imports: [RouterLink], template: `
+ This example uses a [template reference variable](guide/templates) to get access to the `input` element as its value. 1. Next, update the component template to attach an event handler to the "Search" button. - + By binding to the `click` event on the `button` element, you are able to call the `filterResults` function. The argument to the function is the `value` property of the `filter` template variable. Specifically, the `.value` property from the `input` HTML element. diff --git a/adev/src/content/tutorials/first-app/steps/13-search/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/13-search/src/app/home/home.ts index d8375a3d475..43a2b0002cf 100644 --- a/adev/src/content/tutorials/first-app/steps/13-search/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/13-search/src/app/home/home.ts @@ -15,7 +15,7 @@ import {HousingService} from '../housing.service';
@for(housingLocation of housingLocationList; track $index) { - + }
`, diff --git a/adev/src/content/tutorials/first-app/steps/13-search/src/app/housing-location/housing-location.ts b/adev/src/content/tutorials/first-app/steps/13-search/src/app/housing-location/housing-location.ts index 00f2348cf7b..21bb0dc6532 100644 --- a/adev/src/content/tutorials/first-app/steps/13-search/src/app/housing-location/housing-location.ts +++ b/adev/src/content/tutorials/first-app/steps/13-search/src/app/housing-location/housing-location.ts @@ -1,10 +1,10 @@ import {Component, input} from '@angular/core'; import {HousingLocationInfo} from '../housinglocation'; -import {RouterModule} from '@angular/router'; +import {RouterLink} from '@angular/router'; @Component({ selector: 'app-housing-location', - imports: [RouterModule], + imports: [RouterLink], template: `
- npm install -g json-server - + + ```bash + npm install -g json-server + ``` 1. In the root directory of your project, create a file called `db.json`. This is where you will store the data for the `json-server`. 1. Open `db.json` and copy the following code into the file - + + ```json { - "locations": [ - { - "id": 0, - "name": "Acme Fresh Start Housing", - "city": "Chicago", - "state": "IL", - "photo": "https://angular.dev/assets/images/tutorials/common/bernard-hermant-CLKGGwIBTaY-unsplash.jpg", - "availableUnits": 4, - "wifi": true, - "laundry": true - }, - { - "id": 1, - "name": "A113 Transitional Housing", - "city": "Santa Monica", - "state": "CA", - "photo": "https://angular.dev/assets/images/tutorials/common/brandon-griggs-wR11KBaB86U-unsplash.jpg", - "availableUnits": 0, - "wifi": false, - "laundry": true - }, - { - "id": 2, - "name": "Warm Beds Housing Support", - "city": "Juneau", - "state": "AK", - "photo": "https://angular.dev/assets/images/tutorials/common/i-do-nothing-but-love-lAyXdl1-Wmc-unsplash.jpg", - "availableUnits": 1, - "wifi": false, - "laundry": false - }, - { - "id": 3, - "name": "Homesteady Housing", - "city": "Chicago", - "state": "IL", - "photo": "https://angular.dev/assets/images/tutorials/common/ian-macdonald-W8z6aiwfi1E-unsplash.jpg", - "availableUnits": 1, - "wifi": true, - "laundry": false - }, - { - "id": 4, - "name": "Happy Homes Group", - "city": "Gary", - "state": "IN", - "photo": "https://angular.dev/assets/images/tutorials/common/krzysztof-hepner-978RAXoXnH4-unsplash.jpg", - "availableUnits": 1, - "wifi": true, - "laundry": false - }, - { - "id": 5, - "name": "Hopeful Apartment Group", - "city": "Oakland", - "state": "CA", - "photo": "https://angular.dev/assets/images/tutorials/common/r-architecture-JvQ0Q5IkeMM-unsplash.jpg", - "availableUnits": 2, - "wifi": true, - "laundry": true - }, - { - "id": 6, - "name": "Seriously Safe Towns", - "city": "Oakland", - "state": "CA", - "photo": "https://angular.dev/assets/images/tutorials/common/phil-hearing-IYfp2Ixe9nM-unsplash.jpg", - "availableUnits": 5, - "wifi": true, - "laundry": true - }, - { - "id": 7, - "name": "Hopeful Housing Solutions", - "city": "Oakland", - "state": "CA", - "photo": "https://angular.dev/assets/images/tutorials/common/r-architecture-GGupkreKwxA-unsplash.jpg", - "availableUnits": 2, - "wifi": true, - "laundry": true - }, - { - "id": 8, - "name": "Seriously Safe Towns", - "city": "Oakland", - "state": "CA", - "photo": "https://angular.dev/assets/images/tutorials/common/saru-robert-9rP3mxf8qWI-unsplash.jpg", - "availableUnits": 10, - "wifi": false, - "laundry": false - }, - { - "id": 9, - "name": "Capital Safe Towns", - "city": "Portland", - "state": "OR", - "photo": "https://angular.dev/assets/images/tutorials/common/webaliser-_TPTXZd9mOo-unsplash.jpg", - "availableUnits": 6, - "wifi": true, - "laundry": true + "locations": [ + { + "id": 0, + "name": "Acme Fresh Start Housing", + "city": "Chicago", + "state": "IL", + "photo": "https://angular.dev/assets/images/tutorials/common/bernard-hermant-CLKGGwIBTaY-unsplash.jpg", + "availableUnits": 4, + "wifi": true, + "laundry": true + }, + { + "id": 1, + "name": "A113 Transitional Housing", + "city": "Santa Monica", + "state": "CA", + "photo": "https://angular.dev/assets/images/tutorials/common/brandon-griggs-wR11KBaB86U-unsplash.jpg", + "availableUnits": 0, + "wifi": false, + "laundry": true + }, + { + "id": 2, + "name": "Warm Beds Housing Support", + "city": "Juneau", + "state": "AK", + "photo": "https://angular.dev/assets/images/tutorials/common/i-do-nothing-but-love-lAyXdl1-Wmc-unsplash.jpg", + "availableUnits": 1, + "wifi": false, + "laundry": false + }, + { + "id": 3, + "name": "Homesteady Housing", + "city": "Chicago", + "state": "IL", + "photo": "https://angular.dev/assets/images/tutorials/common/ian-macdonald-W8z6aiwfi1E-unsplash.jpg", + "availableUnits": 1, + "wifi": true, + "laundry": false + }, + { + "id": 4, + "name": "Happy Homes Group", + "city": "Gary", + "state": "IN", + "photo": "https://angular.dev/assets/images/tutorials/common/krzysztof-hepner-978RAXoXnH4-unsplash.jpg", + "availableUnits": 1, + "wifi": true, + "laundry": false + }, + { + "id": 5, + "name": "Hopeful Apartment Group", + "city": "Oakland", + "state": "CA", + "photo": "https://angular.dev/assets/images/tutorials/common/r-architecture-JvQ0Q5IkeMM-unsplash.jpg", + "availableUnits": 2, + "wifi": true, + "laundry": true + }, + { + "id": 6, + "name": "Seriously Safe Towns", + "city": "Oakland", + "state": "CA", + "photo": "https://angular.dev/assets/images/tutorials/common/phil-hearing-IYfp2Ixe9nM-unsplash.jpg", + "availableUnits": 5, + "wifi": true, + "laundry": true + }, + { + "id": 7, + "name": "Hopeful Housing Solutions", + "city": "Oakland", + "state": "CA", + "photo": "https://angular.dev/assets/images/tutorials/common/r-architecture-GGupkreKwxA-unsplash.jpg", + "availableUnits": 2, + "wifi": true, + "laundry": true + }, + { + "id": 8, + "name": "Seriously Safe Towns", + "city": "Oakland", + "state": "CA", + "photo": "https://angular.dev/assets/images/tutorials/common/saru-robert-9rP3mxf8qWI-unsplash.jpg", + "availableUnits": 10, + "wifi": false, + "laundry": false + }, + { + "id": 9, + "name": "Capital Safe Towns", + "city": "Portland", + "state": "OR", + "photo": "https://angular.dev/assets/images/tutorials/common/webaliser-_TPTXZd9mOo-unsplash.jpg", + "availableUnits": 6, + "wifi": true, + "laundry": true + } + ] } - ] - } - + ``` 1. Save this file. 1. Time to test your configuration. From the command line, at the root of your project run the following commands. - - json-server --watch db.json - + ```bash + json-server --watch db.json + ``` 1. In your web browser, navigate to the `http://localhost:3000/locations` and confirm that the response includes the data stored in `db.json`. diff --git a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.ts b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.ts index c9be1236e28..fa549e7c45a 100644 --- a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.ts +++ b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.ts @@ -13,7 +13,7 @@ import {RouterLink, RouterOutlet} from '@angular/router';
- +
`, diff --git a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.ts index 6949c27ea75..572baab9004 100644 --- a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.ts @@ -15,7 +15,7 @@ import {HousingService} from '../housing.service';
@for(housingLocation of filteredLocationList; track $index) { - + }
`, diff --git a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.ts b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.ts index 13568524465..09605664854 100644 --- a/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.ts +++ b/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.ts @@ -1,10 +1,10 @@ import {Component, input} from '@angular/core'; import {HousingLocationInfo} from '../housinglocation'; -import {RouterModule} from '@angular/router'; +import {RouterLink} from '@angular/router'; @Component({ selector: 'app-housing-location', - imports: [RouterModule], + imports: [RouterLink], template: `
- +
`, diff --git a/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.ts b/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.ts index 7f8e1ed01b1..0680f17f43f 100644 --- a/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.ts +++ b/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.ts @@ -15,7 +15,7 @@ import {HousingService} from '../housing.service';
@for(housingLocation of filteredLocationList; track $index) { - + }
`, diff --git a/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.ts b/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.ts index 00f2348cf7b..21bb0dc6532 100644 --- a/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.ts +++ b/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.ts @@ -1,10 +1,10 @@ import {Component, input} from '@angular/core'; import {HousingLocationInfo} from '../housinglocation'; -import {RouterModule} from '@angular/router'; +import {RouterLink} from '@angular/router'; @Component({ selector: 'app-housing-location', - imports: [RouterModule], + imports: [RouterLink], template: `
User - + `, imports: [RouterOutlet], }) diff --git a/adev/src/content/tutorials/learn-angular/steps/13-define-a-route/src/app/app.ts b/adev/src/content/tutorials/learn-angular/steps/13-define-a-route/src/app/app.ts index da5db0dde38..92ab881a771 100644 --- a/adev/src/content/tutorials/learn-angular/steps/13-define-a-route/src/app/app.ts +++ b/adev/src/content/tutorials/learn-angular/steps/13-define-a-route/src/app/app.ts @@ -9,7 +9,7 @@ import {RouterOutlet} from '@angular/router'; | User - + `, imports: [RouterOutlet], }) diff --git a/adev/src/content/tutorials/playground/3-minigame/src/game.html b/adev/src/content/tutorials/playground/3-minigame/src/game.html index 671f904ff9d..7c5e3701cec 100644 --- a/adev/src/content/tutorials/playground/3-minigame/src/game.html +++ b/adev/src/content/tutorials/playground/3-minigame/src/game.html @@ -14,7 +14,7 @@
@if(rotateVal() >= 20) { -
+
@@ -24,7 +24,7 @@
diff --git a/adev/src/content/tutorials/playground/3-minigame/src/main.ts b/adev/src/content/tutorials/playground/3-minigame/src/main.ts index 9baed226862..b1f1c013325 100644 --- a/adev/src/content/tutorials/playground/3-minigame/src/main.ts +++ b/adev/src/content/tutorials/playground/3-minigame/src/main.ts @@ -1,6 +1,13 @@ import {A11yModule} from '@angular/cdk/a11y'; -import {CommonModule} from '@angular/common'; -import {Component, ElementRef, ViewChild, computed, signal} from '@angular/core'; +import {DecimalPipe} from '@angular/common'; +import { + ChangeDetectionStrategy, + Component, + ElementRef, + computed, + signal, + viewChild, +} from '@angular/core'; import {MatSlideToggleChange, MatSlideToggleModule} from '@angular/material/slide-toggle'; import {bootstrapApplication} from '@angular/platform-browser'; @@ -52,9 +59,10 @@ function getResultQuote(accuracy: number) { @Component({ selector: 'app-root', - imports: [CommonModule, MatSlideToggleModule, A11yModule], + imports: [DecimalPipe, MatSlideToggleModule, A11yModule], styleUrl: 'game.css', templateUrl: 'game.html', + changeDetection: ChangeDetectionStrategy.OnPush, }) export class Playground { protected readonly isGuessModalOpen = signal(false); @@ -75,7 +83,7 @@ export class Playground { quote: "Hi, I'm NG the Angle!", }; - @ViewChild('staticArrow') staticArrow!: ElementRef; + staticArrow = viewChild.required>('staticArrow'); protected readonly totalAccuracyPercentage = computed(() => { const {level, totalAccuracy} = this.gameStats(); @@ -100,6 +108,12 @@ export class Playground { return this.currentInteractions; }); + protected readonly rotation = computed(() => `rotate(${this.rotateVal()}deg)`); + + protected readonly indicatorStyle = computed(() => 0.487 * this.rotateVal() - 179.5); + + protected readonly indicatorRotation = computed(() => `rotate(${253 + this.rotateVal()}deg)`); + constructor() { this.resetGame(); } @@ -109,18 +123,6 @@ export class Playground { this.rotateVal.set(40); } - getRotation() { - return `rotate(${this.rotateVal()}deg)`; - } - - getIndicatorStyle() { - return 0.487 * this.rotateVal() - 179.5; - } - - getIndicatorRotation() { - return `rotate(${253 + this.rotateVal()}deg)`; - } - mouseDown() { this.isDragging = true; } @@ -133,8 +135,8 @@ export class Playground { const vh30 = 0.3 * document.documentElement.clientHeight; if (!this.isDragging) return; - let pointX = e.pageX - (this.staticArrow.nativeElement.offsetLeft + 2.5); - let pointY = e.pageY - (this.staticArrow.nativeElement.offsetTop + vh30); + let pointX = e.pageX - (this.staticArrow().nativeElement.offsetLeft + 2.5); + let pointY = e.pageY - (this.staticArrow().nativeElement.offsetTop + vh30); let calculatedAngle = 0; if (pointX >= 0 && pointY < 0) { diff --git a/adev/src/content/tutorials/signals/steps/2-deriving-state-with-computed-signals/README.md b/adev/src/content/tutorials/signals/steps/2-deriving-state-with-computed-signals/README.md index e0a5bc5cf07..8305008d1e5 100644 --- a/adev/src/content/tutorials/signals/steps/2-deriving-state-with-computed-signals/README.md +++ b/adev/src/content/tutorials/signals/steps/2-deriving-state-with-computed-signals/README.md @@ -68,7 +68,7 @@ The template already has placeholders showing "Loading...". Replace them with yo 1. For notifications, replace `Loading...` with an @if block: -```html +```angular-html @if (notificationsEnabled()) { Enabled } @else { @@ -78,13 +78,13 @@ The template already has placeholders showing "Loading...". Replace them with yo 2. For the message, replace `Loading...` with: -```html +```angular-html {{ statusMessage() }} ``` 3. For working hours, replace `Loading...` with an @if block: -```html +```angular-html @if (isWithinWorkingHours()) { Yes } @else { diff --git a/adev/src/content/tutorials/signals/steps/3-deriving-state-with-linked-signals/README.md b/adev/src/content/tutorials/signals/steps/3-deriving-state-with-linked-signals/README.md index 5623d00ed35..f1980a4063a 100644 --- a/adev/src/content/tutorials/signals/steps/3-deriving-state-with-linked-signals/README.md +++ b/adev/src/content/tutorials/signals/steps/3-deriving-state-with-linked-signals/README.md @@ -50,7 +50,7 @@ This is the key difference: computed signals are read-only, but linked signals c Update your template to add a toggle button for notifications: -```html +```angular-html
Notifications: diff --git a/adev/src/content/tutorials/signals/steps/4-managing-async-data-with-signals/README.md b/adev/src/content/tutorials/signals/steps/4-managing-async-data-with-signals/README.md index 93a79e4e66f..da3a520b60e 100644 --- a/adev/src/content/tutorials/signals/steps/4-managing-async-data-with-signals/README.md +++ b/adev/src/content/tutorials/signals/steps/4-managing-async-data-with-signals/README.md @@ -75,7 +75,7 @@ Part 1. **Add click handlers to the buttons:** Part 2. **Replace the placeholder with resource state handling:** -```html +```angular-html @if (isLoading()) {

Loading user...

} @else if (hasError()) { diff --git a/adev/src/content/tutorials/signals/steps/5-component-communication-with-signals/README.md b/adev/src/content/tutorials/signals/steps/5-component-communication-with-signals/README.md index 528af3b1b34..172af2ec822 100644 --- a/adev/src/content/tutorials/signals/steps/5-component-communication-with-signals/README.md +++ b/adev/src/content/tutorials/signals/steps/5-component-communication-with-signals/README.md @@ -27,7 +27,7 @@ Notice how `input.required()` creates an input that must be provided, while `inp Update the template in `product-card` to display the signal input values. -```html +```angular-html

{{ name() }}

\${{ price() }}

diff --git a/adev/src/content/tutorials/signals/steps/6-two-way-binding-with-model-signals/README.md b/adev/src/content/tutorials/signals/steps/6-two-way-binding-with-model-signals/README.md index d68cdee85f2..960e462f37a 100644 --- a/adev/src/content/tutorials/signals/steps/6-two-way-binding-with-model-signals/README.md +++ b/adev/src/content/tutorials/signals/steps/6-two-way-binding-with-model-signals/README.md @@ -83,7 +83,7 @@ Part 1. **Uncomment the checkboxes and add two-way binding:** Part 2. **Replace the `???` placeholders with @if blocks:** -```html +```angular-html @if (agreedToTerms()) { Yes } @else { diff --git a/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/README.md b/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/README.md index 6d6c5541263..15cc2268338 100644 --- a/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/README.md +++ b/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/README.md @@ -60,7 +60,7 @@ These methods read the current cart state using `cartItems()` and update quantit Update the main app component in `app.ts` to use the cart service and display the cart component. -```ts +```angular-ts import {Component, inject} from '@angular/core'; import {CartStore} from './cart-store'; import {CartDisplay} from './cart-display'; diff --git a/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/answer/src/app/app.ts b/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/answer/src/app/app.ts index 966a8fcc36b..e48b2d64725 100644 --- a/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/answer/src/app/app.ts +++ b/adev/src/content/tutorials/signals/steps/7-using-signals-with-services/answer/src/app/app.ts @@ -15,7 +15,7 @@ import {CartDisplay} from './cart-display';
- +
`, diff --git a/adev/src/content/tutorials/signals/steps/8-using-signals-with-directives/README.md b/adev/src/content/tutorials/signals/steps/8-using-signals-with-directives/README.md index aae2a5d690f..5f6dba3abc3 100644 --- a/adev/src/content/tutorials/signals/steps/8-using-signals-with-directives/README.md +++ b/adev/src/content/tutorials/signals/steps/8-using-signals-with-directives/README.md @@ -76,7 +76,7 @@ The host bindings automatically re-evaluate when the signals change - just like Update the app template to demonstrate the reactive directive: -```ts +```angular-ts template: `

Directive with Signals