_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
angular/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg_0_2207
<svg width="151" height="44" viewBox="0 0 151 44" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M6.15532 33.2946C5.25369 33.2946 4.58006 32.5707 4.58006 31.6701V24.0152C4.58006 19.5469 4.35206 20.6276 7.59585 17.4236C21.7317 4.06732 16.2425 4.24744 29.6149 18.054C32.0434 20.7627 31.9985 19.4534 31.9985 23.8316V31.6667C31.9985 32.5707 31.28 33.2912 30.3749 33.2912H6.15532V33.2946Z" fill="#605DC8"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M30.896 35.1547L5.73676 35.2586C4.80059 35.2621 3.75042 35.8232 3.37388 36.5229L2.90061 37.4027L0.537726 41.7878L0.140457 42.529C-0.236085 43.2253 0.164639 43.7829 1.10081 43.7795L26.26 43.6756C27.1962 43.6721 28.2464 43.111 28.6229 42.4113L29.0962 41.5315L31.4591 37.1463L31.8563 36.4051C32.2329 35.7089 31.8321 35.1512 30.896 35.1547Z" fill="#605DC8"/> <path d="M2.54861 18.7156C2.23079 18.7156 1.90952 18.629 1.6228 18.4454C0.821352 17.9363 0.5899 16.859 1.09771 16.0554C1.46389 15.4701 2.70061 14.2231 5.50912 11.4659L6.39693 10.5931C8.73218 8.38318 10.5147 6.56817 11.9449 5.10646C15.1679 1.81587 16.7985 0.153263 18.9023 0.222538C20.9888 0.277958 22.4362 1.92325 25.3138 5.19651C26.7267 6.8037 28.4816 8.8023 30.8514 11.2477C30.8652 11.265 30.8825 11.2789 30.8963 11.2962C31.228 11.6634 31.715 12.2003 32.2401 12.7752C33.9743 14.6734 34.8206 15.6086 35.0763 15.9688C35.629 16.7413 35.4494 17.8185 34.679 18.3727C33.9087 18.9234 32.8343 18.7468 32.2816 17.9744C32.0639 17.6869 30.5889 16.0693 29.708 15.1064C29.1863 14.5348 28.6993 14.0014 28.3642 13.6308C25.9495 11.1369 24.1704 9.11057 22.7368 7.4826C21.0233 5.5325 19.4032 3.68977 18.809 3.67245H18.8021C18.1699 3.67245 16.3356 5.54289 14.3976 7.52417C12.9467 9.00666 11.14 10.8494 8.78054 13.0766L7.91001 13.9321C6.74929 15.0717 4.33804 17.4375 3.97877 17.9293C3.65405 18.4454 3.10824 18.7225 2.54515 18.7225L2.54861 18.7156Z" fill="#605DC8"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M22.0976 33.2115V26.0588C22.0976 25.4665 21.6174 24.985 21.0267 24.985H15.1955C14.6047 24.985 14.1246 25.4665 14.1246 26.0588V33.2115C14.1246 33.2704 14.1142 33.3293 14.0969 33.3847H22.1252C22.1079 33.3293 22.0976 33.2739 22.0976 33.2115Z" fill="white"/>
{ "end_byte": 2207, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg_2208_5628
<path d="M58.9784 10.0512V32.2205H54.5319V22.7874H45.0353V32.2205H40.5887V10.0512H45.0353V19.1666H54.5319V10.0512H58.9784ZM70.8506 32.5063C69.1567 32.5063 67.6322 32.1358 66.277 31.3947C64.9219 30.6324 63.8526 29.5631 63.0692 28.1868C62.3069 26.8105 61.9258 25.2224 61.9258 23.4226C61.9258 21.6228 62.3175 20.0348 63.1009 18.6585C63.9055 17.2821 64.996 16.2234 66.3723 15.4823C67.7486 14.7201 69.2838 14.3389 70.9777 14.3389C72.6716 14.3389 74.2067 14.7201 75.5831 15.4823C76.9594 16.2234 78.0393 17.2821 78.8227 18.6585C79.6273 20.0348 80.0296 21.6228 80.0296 23.4226C80.0296 25.2224 79.6167 26.8105 78.7909 28.1868C77.9863 29.5631 76.8853 30.6324 75.4878 31.3947C74.1115 32.1358 72.5657 32.5063 70.8506 32.5063ZM70.8506 28.6315C71.6553 28.6315 72.4069 28.4409 73.1057 28.0597C73.8256 27.6574 74.3973 27.0646 74.8208 26.2811C75.2443 25.4977 75.456 24.5449 75.456 23.4226C75.456 21.7499 75.0114 20.4688 74.122 19.5795C73.2539 18.669 72.1846 18.2138 70.9142 18.2138C69.6437 18.2138 68.5744 18.669 67.7063 19.5795C66.8593 20.4688 66.4358 21.7499 66.4358 23.4226C66.4358 25.0954 66.8487 26.387 67.6745 27.2975C68.5215 28.1868 69.5802 28.6315 70.8506 28.6315ZM104.825 14.3707C106.985 14.3707 108.721 15.0377 110.034 16.3717C111.368 17.6844 112.035 19.5266 112.035 21.8981V32.2205H107.589V22.5016C107.589 21.1252 107.239 20.0771 106.54 19.3572C105.842 18.6161 104.889 18.2456 103.682 18.2456C102.475 18.2456 101.512 18.6161 100.792 19.3572C100.093 20.0771 99.7436 21.1252 99.7436 22.5016V32.2205H95.297V22.5016C95.297 21.1252 94.9477 20.0771 94.2489 19.3572C93.5502 18.6161 92.5974 18.2456 91.3904 18.2456C90.1623 18.2456 89.1883 18.6161 88.4684 19.3572C87.7697 20.0771 87.4203 21.1252 87.4203 22.5016V32.2205H82.9737V14.6248H87.4203V16.7528C87.992 16.0117 88.7225 15.4294 89.6118 15.0059C90.5223 14.5824 91.5175 14.3707 92.5974 14.3707C93.9737 14.3707 95.2018 14.6671 96.2816 15.26C97.3615 15.8317 98.1979 16.6575 98.7908 17.7374C99.3625 16.721 100.188 15.9058 101.268 15.2918C102.369 14.6777 103.555 14.3707 104.825 14.3707ZM132.294 23.0415C132.294 23.6767 132.252 24.2484 132.167 24.7566H119.304C119.41 26.027 119.854 27.0222 120.638 27.7421C121.421 28.4621 122.385 28.822 123.528 28.822C125.18 28.822 126.355 28.1127 127.053 26.694H131.849C131.341 28.3879 130.367 29.7854 128.927 30.8865C127.488 31.9664 125.72 32.5063 123.623 32.5063C121.929 32.5063 120.405 32.1358 119.05 31.3947C117.716 30.6324 116.668 29.5631 115.905 28.1868C115.164 26.8105 114.794 25.2224 114.794 23.4226C114.794 21.6017 115.164 20.003 115.905 18.6267C116.646 17.2504 117.684 16.1917 119.018 15.4506C120.352 14.7095 121.887 14.3389 123.623 14.3389C125.296 14.3389 126.789 14.6989 128.102 15.4188C129.436 16.1387 130.462 17.1657 131.182 18.4996C131.924 19.8124 132.294 21.3264 132.294 23.0415ZM127.689 21.771C127.668 20.6276 127.255 19.7172 126.45 19.0396C125.645 18.3408 124.661 17.9915 123.496 17.9915C122.395 17.9915 121.464 18.3303 120.701 19.0078C119.96 19.6642 119.505 20.5853 119.336 21.771H127.689ZM141.955 32.5063C140.516 32.5063 139.224 32.2522 138.081 31.744C136.937 31.2147 136.027 30.5054 135.349 29.616C134.693 28.7267 134.333 27.7421 134.269 26.6623H138.748C138.832 27.3398 139.16 27.9009 139.732 28.3456C140.325 28.7903 141.055 29.0126 141.924 29.0126C142.771 29.0126 143.427 28.8432 143.893 28.5044C144.38 28.1656 144.623 27.7316 144.623 27.2022C144.623 26.6305 144.327 26.207 143.734 25.9318C143.162 25.6353 142.241 25.3177 140.971
{ "end_byte": 5628, "start_byte": 2208, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg_5629_6611
24.9789C139.658 24.6613 138.578 24.3331 137.731 23.9943C136.905 23.6555 136.185 23.1368 135.571 22.438C134.979 21.7393 134.682 20.797 134.682 19.6113C134.682 18.6373 134.957 17.748 135.508 16.9434C136.08 16.1387 136.884 15.5035 137.922 15.0377C138.98 14.5719 140.219 14.3389 141.638 14.3389C143.734 14.3389 145.407 14.8683 146.656 15.927C147.905 16.9645 148.593 18.3726 148.721 20.1512H144.465C144.401 19.4525 144.105 18.902 143.575 18.4996C143.067 18.0762 142.379 17.8644 141.511 17.8644C140.706 17.8644 140.081 18.0126 139.637 18.3091C139.213 18.6055 139.002 19.0184 139.002 19.5478C139.002 20.1406 139.298 20.5959 139.891 20.9135C140.484 21.2099 141.405 21.517 142.654 21.8346C143.925 22.1522 144.973 22.4804 145.798 22.8192C146.624 23.1579 147.334 23.6873 147.926 24.4072C148.541 25.106 148.858 26.0376 148.879 27.2022C148.879 28.2186 148.593 29.129 148.022 29.9337C147.471 30.7383 146.667 31.3735 145.608 31.8393C144.57 32.284 143.353 32.5063 141.955 32.5063Z" fill="#605DC8"/>
{ "end_byte": 6611, "start_byte": 5629, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg_6612_6619
</svg>
{ "end_byte": 6619, "start_byte": 6612, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/07-dynamic-template-values/src/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/README.md_0_535
# Add HTTP communication to your app This tutorial demonstrates how to integrate HTTP and an API into your app. Up until this point your app has read data from a static array in an Angular service. The next step is to use a JSON server that your app will communicate with over HTTP. The HTTP request will simulate the experience of working with data from a server. <docs-video src="https://www.youtube.com/embed/5K10oYJ5Y-E?si=TiuNKx_teR9baO7k"/> IMPORTANT: We recommend using your local environment for this step of the tutorial.
{ "end_byte": 535, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/README.md" }
angular/adev/src/content/tutorials/first-app/steps/14-http/README.md_536_9428
## What you'll learn Your app will use data from a JSON server <docs-workflow> <docs-step title="Configure the JSON server"> JSON Server is an open source tool used to create mock REST APIs. You'll use it to serve the housing location data that is currently stored in the housing service. 1. Install `json-server` from npm by using the following command. <docs-code language="bash"> npm install -g json-server </docs-code> 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 <docs-code language="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 } ] } </docs-code> 1. Save this file. 1. Time to test your configuration. From the command line, at the root of your project run the following commands. <docs-code language="bash"> json-server --watch db.json </docs-code> 1. In your web browser, navigate to the `http://localhost:3000/locations` and confirm that the response includes the data stored in `db.json`. If you have any trouble with your configuration, you can find more details in the [official documentation](https://www.npmjs.com/package/json-server). </docs-step> <docs-step title="Update service to use web server instead of local array"> The data source has been configured, the next step is to update your web app to connect to it use the data. 1. In `src/app/housing.service.ts`, make the following changes: 1. Update the code to remove `housingLocationList` property and the array containing the data. 1. Add a string property called `url` and set its value to `'http://localhost:3000/locations'` <docs-code language="javascript"> url = 'http://localhost:3000/locations'; </docs-code> This code will result in errors in the rest of the file because it depends on the `housingLocationList` property. We're going to update the service methods next. 1. Update the `getAllHousingLocations` function to make a call to the web server you configured. <docs-code header="" path="adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts" visibleLines="[10,13]"/> The code now uses asynchronous code to make a **GET** request over HTTP. HELPFUL: For this example, the code uses `fetch`. For more advanced use cases consider using `HttpClient` provided by Angular. 1. Update the `getHousingLocationsById` function to make a call to the web server you configured. <docs-code header="" path="adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts" visibleLines="[15,18]"/> 1. Once all the updates are complete, your updated service should match the following code. <docs-code header="Final version of housing.service.ts" path="adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts" visibleLines="[1,24]" /> </docs-step> <docs-step title="Update the components to use asynchronous calls to the housing service"> The server is now reading data from the HTTP request but the components that rely on the service now have errors because they were programmed to use the synchronous version of the service. 1. In `src/app/home/home.component.ts`, update the `constructor` to use the new asynchronous version of the `getAllHousingLocations` method. <docs-code header="" path="adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.component.ts" visibleLines="[32,37]"/> 1. In `src/app/details/details.component.ts`, update the `constructor` to use the new asynchronous version of the `getHousingLocationById` method. <docs-code header="" path="adev/src/content/tutorials/first-app/steps/14-http/src-final/app/details/details.component.ts" visibleLines="[61,66]"/> 1. Save your code. 1. Open the application in the browser and confirm that it runs without any errors. </docs-step> </docs-workflow> Note: This lesson relies on the `fetch` browser API. For the support of interceptors, please refer to the [Http Client documentation](/guide/http) Summary: In this lesson, you updated your app to use a local web server (`json-server`), and use asynchronous service methods to retrieve data. Congratulations! You've successfully completed this tutorial and are ready to continue your journey with building even more complex Angular Apps. If you would like to learn more, please consider completing some of Angular's other developer [tutorials](tutorials) and [guides](overview).
{ "end_byte": 9428, "start_byte": 536, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/README.md" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/index.html_0_427
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Homes</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> <link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet"> </head> <body> <app-root></app-root> </body> </html>
{ "end_byte": 427, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/index.html" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/main.ts_0_536
/* * Protractor support is deprecated in Angular. * Protractor is used in this example for compatibility with Angular documentation tools. */ import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {provideRouter} from '@angular/router'; import routeConfig from './app/routes'; bootstrapApplication(AppComponent, { providers: [provideProtractorTestingSupport(), provideRouter(routeConfig)], }).catch((err) => console.error(err));
{ "end_byte": 536, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/main.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/styles.css_0_443
/* You can add global styles to this file, and also import other style files */ * { margin: 0; padding: 0; } body { font-family: 'Be Vietnam Pro', sans-serif; } :root { --primary-color: #605DC8; --secondary-color: #8B89E6; --accent-color: #e8e7fa; --shadow-color: #E8E8E8; } button.primary { padding: 10px; border: solid 1px var(--primary-color); background: var(--primary-color); color: white; border-radius: 8px; }
{ "end_byte": 443, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/styles.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/routes.ts_0_389
import {Routes} from '@angular/router'; import {HomeComponent} from './home/home.component'; import {DetailsComponent} from './details/details.component'; const routeConfig: Routes = [ { path: '', component: HomeComponent, title: 'Home page', }, { path: 'details/:id', component: DetailsComponent, title: 'Home details', }, ]; export default routeConfig;
{ "end_byte": 389, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/routes.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housinglocation.ts_0_180
export interface HousingLocation { id: number; name: string; city: string; state: string; photo: string; availableUnits: number; wifi: boolean; laundry: boolean; }
{ "end_byte": 180, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housinglocation.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts_0_687
import {Injectable} from '@angular/core'; import {HousingLocation} from './housinglocation'; @Injectable({ providedIn: 'root', }) export class HousingService { url = 'http://localhost:3000/locations'; async getAllHousingLocations(): Promise<HousingLocation[]> { const data = await fetch(this.url); return (await data.json()) ?? []; } async getHousingLocationById(id: number): Promise<HousingLocation | undefined> { const data = await fetch(`${this.url}/${id}`); return (await data.json()) ?? {}; } submitApplication(firstName: string, lastName: string, email: string) { // tslint:disable-next-line console.log(firstName, lastName, email); } }
{ "end_byte": 687, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing.service.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.component.ts_0_671
import {Component} from '@angular/core'; import {HomeComponent} from './home/home.component'; import {RouterLink, RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', standalone: true, imports: [HomeComponent, RouterLink, RouterOutlet], template: ` <main> <a [routerLink]="['/']"> <header class="brand-name"> <img class="brand-logo" src="/assets/logo.svg" alt="logo" aria-hidden="true" /> </header> </a> <section class="content"> <router-outlet></router-outlet> </section> </main> `, styleUrls: ['./app.component.css'], }) export class AppComponent { title = 'homes'; }
{ "end_byte": 671, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.component.css_0_213
:host { --content-padding: 10px; } header { display: block; height: 60px; padding: var(--content-padding); box-shadow: 0px 5px 25px var(--shadow-color); } .content { padding: var(--content-padding); }
{ "end_byte": 213, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/app.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.component.ts_0_1615
import {Component, inject} from '@angular/core'; import {CommonModule} from '@angular/common'; import {HousingLocationComponent} from '../housing-location/housing-location.component'; import {HousingLocation} from '../housinglocation'; import {HousingService} from '../housing.service'; @Component({ selector: 'app-home', standalone: true, imports: [CommonModule, HousingLocationComponent], template: ` <section> <form> <input type="text" placeholder="Filter by city" #filter /> <button class="primary" type="button" (click)="filterResults(filter.value)">Search</button> </form> </section> <section class="results"> <app-housing-location *ngFor="let housingLocation of filteredLocationList" [housingLocation]="housingLocation" ></app-housing-location> </section> `, styleUrls: ['./home.component.css'], }) export class HomeComponent { housingLocationList: HousingLocation[] = []; housingService: HousingService = inject(HousingService); filteredLocationList: HousingLocation[] = []; constructor() { this.housingService.getAllHousingLocations().then((housingLocationList: HousingLocation[]) => { this.housingLocationList = housingLocationList; this.filteredLocationList = housingLocationList; }); } filterResults(text: string) { if (!text) { this.filteredLocationList = this.housingLocationList; return; } this.filteredLocationList = this.housingLocationList.filter((housingLocation) => housingLocation?.city.toLowerCase().includes(text.toLowerCase()), ); } }
{ "end_byte": 1615, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.component.css_0_746
.results { display: grid; column-gap: 14px; row-gap: 14px; grid-template-columns: repeat(auto-fill, minmax(400px, 400px)); margin-top: 50px; justify-content: space-around; } input[type="text"] { border: solid 1px var(--primary-color); padding: 10px; border-radius: 8px; margin-right: 4px; display: inline-block; width: 30%; } button { padding: 10px; border: solid 1px var(--primary-color); background: var(--primary-color); color: white; border-radius: 8px; } @media (min-width: 500px) and (max-width: 768px) { .results { grid-template-columns: repeat(2, 1fr); } input[type="text"] { width: 70%; } } @media (max-width: 499px) { .results { grid-template-columns: 1fr; } }
{ "end_byte": 746, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/home/home.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.component.css_0_583
.listing { background: var(--accent-color); border-radius: 30px; padding-bottom: 30px; } .listing-heading { color: var(--primary-color); padding: 10px 20px 0 20px; } .listing-photo { height: 250px; width: 100%; object-fit: cover; border-radius: 30px 30px 0 0; } .listing-location { padding: 10px 20px 20px 20px; } .listing-location::before { content: url("/assets/location-pin.svg") / ""; } section.listing a { padding-left: 20px; text-decoration: none; color: var(--primary-color); } section.listing a::after { content: "\203A"; margin-left: 5px; }
{ "end_byte": 583, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.component.ts_0_908
import {Component, Input} from '@angular/core'; import {CommonModule} from '@angular/common'; import {HousingLocation} from '../housinglocation'; import {RouterModule} from '@angular/router'; @Component({ selector: 'app-housing-location', standalone: true, imports: [CommonModule, RouterModule], template: ` <section class="listing"> <img class="listing-photo" [src]="housingLocation.photo" alt="Exterior photo of {{ housingLocation.name }}" crossorigin /> <h2 class="listing-heading">{{ housingLocation.name }}</h2> <p class="listing-location">{{ housingLocation.city }}, {{ housingLocation.state }}</p> <a [routerLink]="['/details', housingLocation.id]">Learn More</a> </section> `, styleUrls: ['./housing-location.component.css'], }) export class HousingLocationComponent { @Input() housingLocation!: HousingLocation; }
{ "end_byte": 908, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/housing-location/housing-location.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/details/details.component.ts_0_2718
import {Component, inject} from '@angular/core'; import {CommonModule} from '@angular/common'; import {ActivatedRoute} from '@angular/router'; import {HousingService} from '../housing.service'; import {HousingLocation} from '../housinglocation'; import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms'; @Component({ selector: 'app-details', standalone: true, imports: [CommonModule, ReactiveFormsModule], template: ` <article> <img class="listing-photo" [src]="housingLocation?.photo" alt="Exterior photo of {{ housingLocation?.name }}" crossorigin /> <section class="listing-description"> <h2 class="listing-heading">{{ housingLocation?.name }}</h2> <p class="listing-location">{{ housingLocation?.city }}, {{ housingLocation?.state }}</p> </section> <section class="listing-features"> <h2 class="section-heading">About this housing location</h2> <ul> <li>Units available: {{ housingLocation?.availableUnits }}</li> <li>Does this location have wifi: {{ housingLocation?.wifi }}</li> <li>Does this location have laundry: {{ housingLocation?.laundry }}</li> </ul> </section> <section class="listing-apply"> <h2 class="section-heading">Apply now to live here</h2> <form [formGroup]="applyForm" (submit)="submitApplication()"> <label for="first-name">First Name</label> <input id="first-name" type="text" formControlName="firstName" /> <label for="last-name">Last Name</label> <input id="last-name" type="text" formControlName="lastName" /> <label for="email">Email</label> <input id="email" type="email" formControlName="email" /> <button type="submit" class="primary">Apply now</button> </form> </section> </article> `, styleUrls: ['./details.component.css'], }) export class DetailsComponent { route: ActivatedRoute = inject(ActivatedRoute); housingService = inject(HousingService); housingLocation: HousingLocation | undefined; applyForm = new FormGroup({ firstName: new FormControl(''), lastName: new FormControl(''), email: new FormControl(''), }); constructor() { const housingLocationId = parseInt(this.route.snapshot.params['id'], 10); this.housingService.getHousingLocationById(housingLocationId).then((housingLocation) => { this.housingLocation = housingLocation; }); } submitApplication() { this.housingService.submitApplication( this.applyForm.value.firstName ?? '', this.applyForm.value.lastName ?? '', this.applyForm.value.email ?? '', ); } }
{ "end_byte": 2718, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/details/details.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/details/details.component.css_0_1075
.listing-photo { height: 600px; width: 50%; object-fit: cover; border-radius: 30px; float: right; } .listing-heading { font-size: 48pt; font-weight: bold; margin-bottom: 15px; } .listing-location::before { content: url('/assets/location-pin.svg') / ''; } .listing-location { font-size: 24pt; margin-bottom: 15px; } .listing-features > .section-heading { color: var(--secondary-color); font-size: 24pt; margin-bottom: 15px; } .listing-features { margin-bottom: 20px; } .listing-features li { font-size: 14pt; } li { list-style-type: none; } .listing-apply .section-heading { font-size: 18pt; margin-bottom: 15px; } label, input { display: block; } label { color: var(--secondary-color); font-weight: bold; text-transform: uppercase; font-size: 12pt; } input { font-size: 16pt; margin-bottom: 15px; padding: 10px; width: 400px; border-top: none; border-right: none; border-left: none; border-bottom: solid .3px; } @media (max-width: 1024px) { .listing-photo { width: 100%; height: 400px; } }
{ "end_byte": 1075, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/app/details/details.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/location-pin.svg_0_502
<?xml version="1.0" encoding="UTF-8"?> <svg width="20pt" height="20pt" version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <path d="m50 11.602c-15.398 0-27.898 12.5-27.898 27.898 0 5 1.3008 9.6992 3.6016 13.801l2.8984 4.1992 21.398 30.898 21.801-31.398 2.1992-3.1992c2.5-4.1992 3.8984-9 3.8984-14.199 0-15.5-12.5-28-27.898-28zm0 35.598c-4.1992 0-7.6992-3.3984-7.6992-7.6992s3.3984-7.6992 7.6992-7.6992 7.6992 3.3984 7.6992 7.6992-3.5 7.6992-7.6992 7.6992z" fill="#605cc8"/> </svg>
{ "end_byte": 502, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/location-pin.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg_0_2207
<svg width="151" height="44" viewBox="0 0 151 44" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M6.15532 33.2946C5.25369 33.2946 4.58006 32.5707 4.58006 31.6701V24.0152C4.58006 19.5469 4.35206 20.6276 7.59585 17.4236C21.7317 4.06732 16.2425 4.24744 29.6149 18.054C32.0434 20.7627 31.9985 19.4534 31.9985 23.8316V31.6667C31.9985 32.5707 31.28 33.2912 30.3749 33.2912H6.15532V33.2946Z" fill="#605DC8"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M30.896 35.1547L5.73676 35.2586C4.80059 35.2621 3.75042 35.8232 3.37388 36.5229L2.90061 37.4027L0.537726 41.7878L0.140457 42.529C-0.236085 43.2253 0.164639 43.7829 1.10081 43.7795L26.26 43.6756C27.1962 43.6721 28.2464 43.111 28.6229 42.4113L29.0962 41.5315L31.4591 37.1463L31.8563 36.4051C32.2329 35.7089 31.8321 35.1512 30.896 35.1547Z" fill="#605DC8"/> <path d="M2.54861 18.7156C2.23079 18.7156 1.90952 18.629 1.6228 18.4454C0.821352 17.9363 0.5899 16.859 1.09771 16.0554C1.46389 15.4701 2.70061 14.2231 5.50912 11.4659L6.39693 10.5931C8.73218 8.38318 10.5147 6.56817 11.9449 5.10646C15.1679 1.81587 16.7985 0.153263 18.9023 0.222538C20.9888 0.277958 22.4362 1.92325 25.3138 5.19651C26.7267 6.8037 28.4816 8.8023 30.8514 11.2477C30.8652 11.265 30.8825 11.2789 30.8963 11.2962C31.228 11.6634 31.715 12.2003 32.2401 12.7752C33.9743 14.6734 34.8206 15.6086 35.0763 15.9688C35.629 16.7413 35.4494 17.8185 34.679 18.3727C33.9087 18.9234 32.8343 18.7468 32.2816 17.9744C32.0639 17.6869 30.5889 16.0693 29.708 15.1064C29.1863 14.5348 28.6993 14.0014 28.3642 13.6308C25.9495 11.1369 24.1704 9.11057 22.7368 7.4826C21.0233 5.5325 19.4032 3.68977 18.809 3.67245H18.8021C18.1699 3.67245 16.3356 5.54289 14.3976 7.52417C12.9467 9.00666 11.14 10.8494 8.78054 13.0766L7.91001 13.9321C6.74929 15.0717 4.33804 17.4375 3.97877 17.9293C3.65405 18.4454 3.10824 18.7225 2.54515 18.7225L2.54861 18.7156Z" fill="#605DC8"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M22.0976 33.2115V26.0588C22.0976 25.4665 21.6174 24.985 21.0267 24.985H15.1955C14.6047 24.985 14.1246 25.4665 14.1246 26.0588V33.2115C14.1246 33.2704 14.1142 33.3293 14.0969 33.3847H22.1252C22.1079 33.3293 22.0976 33.2739 22.0976 33.2115Z" fill="white"/>
{ "end_byte": 2207, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg_2208_5628
<path d="M58.9784 10.0512V32.2205H54.5319V22.7874H45.0353V32.2205H40.5887V10.0512H45.0353V19.1666H54.5319V10.0512H58.9784ZM70.8506 32.5063C69.1567 32.5063 67.6322 32.1358 66.277 31.3947C64.9219 30.6324 63.8526 29.5631 63.0692 28.1868C62.3069 26.8105 61.9258 25.2224 61.9258 23.4226C61.9258 21.6228 62.3175 20.0348 63.1009 18.6585C63.9055 17.2821 64.996 16.2234 66.3723 15.4823C67.7486 14.7201 69.2838 14.3389 70.9777 14.3389C72.6716 14.3389 74.2067 14.7201 75.5831 15.4823C76.9594 16.2234 78.0393 17.2821 78.8227 18.6585C79.6273 20.0348 80.0296 21.6228 80.0296 23.4226C80.0296 25.2224 79.6167 26.8105 78.7909 28.1868C77.9863 29.5631 76.8853 30.6324 75.4878 31.3947C74.1115 32.1358 72.5657 32.5063 70.8506 32.5063ZM70.8506 28.6315C71.6553 28.6315 72.4069 28.4409 73.1057 28.0597C73.8256 27.6574 74.3973 27.0646 74.8208 26.2811C75.2443 25.4977 75.456 24.5449 75.456 23.4226C75.456 21.7499 75.0114 20.4688 74.122 19.5795C73.2539 18.669 72.1846 18.2138 70.9142 18.2138C69.6437 18.2138 68.5744 18.669 67.7063 19.5795C66.8593 20.4688 66.4358 21.7499 66.4358 23.4226C66.4358 25.0954 66.8487 26.387 67.6745 27.2975C68.5215 28.1868 69.5802 28.6315 70.8506 28.6315ZM104.825 14.3707C106.985 14.3707 108.721 15.0377 110.034 16.3717C111.368 17.6844 112.035 19.5266 112.035 21.8981V32.2205H107.589V22.5016C107.589 21.1252 107.239 20.0771 106.54 19.3572C105.842 18.6161 104.889 18.2456 103.682 18.2456C102.475 18.2456 101.512 18.6161 100.792 19.3572C100.093 20.0771 99.7436 21.1252 99.7436 22.5016V32.2205H95.297V22.5016C95.297 21.1252 94.9477 20.0771 94.2489 19.3572C93.5502 18.6161 92.5974 18.2456 91.3904 18.2456C90.1623 18.2456 89.1883 18.6161 88.4684 19.3572C87.7697 20.0771 87.4203 21.1252 87.4203 22.5016V32.2205H82.9737V14.6248H87.4203V16.7528C87.992 16.0117 88.7225 15.4294 89.6118 15.0059C90.5223 14.5824 91.5175 14.3707 92.5974 14.3707C93.9737 14.3707 95.2018 14.6671 96.2816 15.26C97.3615 15.8317 98.1979 16.6575 98.7908 17.7374C99.3625 16.721 100.188 15.9058 101.268 15.2918C102.369 14.6777 103.555 14.3707 104.825 14.3707ZM132.294 23.0415C132.294 23.6767 132.252 24.2484 132.167 24.7566H119.304C119.41 26.027 119.854 27.0222 120.638 27.7421C121.421 28.4621 122.385 28.822 123.528 28.822C125.18 28.822 126.355 28.1127 127.053 26.694H131.849C131.341 28.3879 130.367 29.7854 128.927 30.8865C127.488 31.9664 125.72 32.5063 123.623 32.5063C121.929 32.5063 120.405 32.1358 119.05 31.3947C117.716 30.6324 116.668 29.5631 115.905 28.1868C115.164 26.8105 114.794 25.2224 114.794 23.4226C114.794 21.6017 115.164 20.003 115.905 18.6267C116.646 17.2504 117.684 16.1917 119.018 15.4506C120.352 14.7095 121.887 14.3389 123.623 14.3389C125.296 14.3389 126.789 14.6989 128.102 15.4188C129.436 16.1387 130.462 17.1657 131.182 18.4996C131.924 19.8124 132.294 21.3264 132.294 23.0415ZM127.689 21.771C127.668 20.6276 127.255 19.7172 126.45 19.0396C125.645 18.3408 124.661 17.9915 123.496 17.9915C122.395 17.9915 121.464 18.3303 120.701 19.0078C119.96 19.6642 119.505 20.5853 119.336 21.771H127.689ZM141.955 32.5063C140.516 32.5063 139.224 32.2522 138.081 31.744C136.937 31.2147 136.027 30.5054 135.349 29.616C134.693 28.7267 134.333 27.7421 134.269 26.6623H138.748C138.832 27.3398 139.16 27.9009 139.732 28.3456C140.325 28.7903 141.055 29.0126 141.924 29.0126C142.771 29.0126 143.427 28.8432 143.893 28.5044C144.38 28.1656 144.623 27.7316 144.623 27.2022C144.623 26.6305 144.327 26.207 143.734 25.9318C143.162 25.6353 142.241 25.3177 140.971
{ "end_byte": 5628, "start_byte": 2208, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg_5629_6611
24.9789C139.658 24.6613 138.578 24.3331 137.731 23.9943C136.905 23.6555 136.185 23.1368 135.571 22.438C134.979 21.7393 134.682 20.797 134.682 19.6113C134.682 18.6373 134.957 17.748 135.508 16.9434C136.08 16.1387 136.884 15.5035 137.922 15.0377C138.98 14.5719 140.219 14.3389 141.638 14.3389C143.734 14.3389 145.407 14.8683 146.656 15.927C147.905 16.9645 148.593 18.3726 148.721 20.1512H144.465C144.401 19.4525 144.105 18.902 143.575 18.4996C143.067 18.0762 142.379 17.8644 141.511 17.8644C140.706 17.8644 140.081 18.0126 139.637 18.3091C139.213 18.6055 139.002 19.0184 139.002 19.5478C139.002 20.1406 139.298 20.5959 139.891 20.9135C140.484 21.2099 141.405 21.517 142.654 21.8346C143.925 22.1522 144.973 22.4804 145.798 22.8192C146.624 23.1579 147.334 23.6873 147.926 24.4072C148.541 25.106 148.858 26.0376 148.879 27.2022C148.879 28.2186 148.593 29.129 148.022 29.9337C147.471 30.7383 146.667 31.3735 145.608 31.8393C144.57 32.284 143.353 32.5063 141.955 32.5063Z" fill="#605DC8"/>
{ "end_byte": 6611, "start_byte": 5629, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg_6612_6619
</svg>
{ "end_byte": 6619, "start_byte": 6612, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src-final/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/index.html_0_427
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Homes</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> <link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet"> </head> <body> <app-root></app-root> </body> </html>
{ "end_byte": 427, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/index.html" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/main.ts_0_536
/* * Protractor support is deprecated in Angular. * Protractor is used in this example for compatibility with Angular documentation tools. */ import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {provideRouter} from '@angular/router'; import routeConfig from './app/routes'; bootstrapApplication(AppComponent, { providers: [provideProtractorTestingSupport(), provideRouter(routeConfig)], }).catch((err) => console.error(err));
{ "end_byte": 536, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/main.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/styles.css_0_443
/* You can add global styles to this file, and also import other style files */ * { margin: 0; padding: 0; } body { font-family: 'Be Vietnam Pro', sans-serif; } :root { --primary-color: #605DC8; --secondary-color: #8B89E6; --accent-color: #e8e7fa; --shadow-color: #E8E8E8; } button.primary { padding: 10px; border: solid 1px var(--primary-color); background: var(--primary-color); color: white; border-radius: 8px; }
{ "end_byte": 443, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/styles.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/routes.ts_0_389
import {Routes} from '@angular/router'; import {HomeComponent} from './home/home.component'; import {DetailsComponent} from './details/details.component'; const routeConfig: Routes = [ { path: '', component: HomeComponent, title: 'Home page', }, { path: 'details/:id', component: DetailsComponent, title: 'Home details', }, ]; export default routeConfig;
{ "end_byte": 389, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/routes.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/housinglocation.ts_0_180
export interface HousingLocation { id: number; name: string; city: string; state: string; photo: string; availableUnits: number; wifi: boolean; laundry: boolean; }
{ "end_byte": 180, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/housinglocation.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing.service.ts_0_3183
import {Injectable} from '@angular/core'; import {HousingLocation} from './housinglocation'; @Injectable({ providedIn: 'root', }) export class HousingService { readonly baseUrl = 'https://angular.dev/assets/images/tutorials/common'; protected housingLocationList: HousingLocation[] = [ { id: 0, name: 'Acme Fresh Start Housing', city: 'Chicago', state: 'IL', photo: `${this.baseUrl}/bernard-hermant-CLKGGwIBTaY-unsplash.jpg`, availableUnits: 4, wifi: true, laundry: true, }, { id: 1, name: 'A113 Transitional Housing', city: 'Santa Monica', state: 'CA', photo: `${this.baseUrl}/brandon-griggs-wR11KBaB86U-unsplash.jpg`, availableUnits: 0, wifi: false, laundry: true, }, { id: 2, name: 'Warm Beds Housing Support', city: 'Juneau', state: 'AK', photo: `${this.baseUrl}/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: `${this.baseUrl}/ian-macdonald-W8z6aiwfi1E-unsplash.jpg`, availableUnits: 1, wifi: true, laundry: false, }, { id: 4, name: 'Happy Homes Group', city: 'Gary', state: 'IN', photo: `${this.baseUrl}/krzysztof-hepner-978RAXoXnH4-unsplash.jpg`, availableUnits: 1, wifi: true, laundry: false, }, { id: 5, name: 'Hopeful Apartment Group', city: 'Oakland', state: 'CA', photo: `${this.baseUrl}/r-architecture-JvQ0Q5IkeMM-unsplash.jpg`, availableUnits: 2, wifi: true, laundry: true, }, { id: 6, name: 'Seriously Safe Towns', city: 'Oakland', state: 'CA', photo: `${this.baseUrl}/phil-hearing-IYfp2Ixe9nM-unsplash.jpg`, availableUnits: 5, wifi: true, laundry: true, }, { id: 7, name: 'Hopeful Housing Solutions', city: 'Oakland', state: 'CA', photo: `${this.baseUrl}/r-architecture-GGupkreKwxA-unsplash.jpg`, availableUnits: 2, wifi: true, laundry: true, }, { id: 8, name: 'Seriously Safe Towns', city: 'Oakland', state: 'CA', photo: `${this.baseUrl}/saru-robert-9rP3mxf8qWI-unsplash.jpg`, availableUnits: 10, wifi: false, laundry: false, }, { id: 9, name: 'Capital Safe Towns', city: 'Portland', state: 'OR', photo: `${this.baseUrl}/webaliser-_TPTXZd9mOo-unsplash.jpg`, availableUnits: 6, wifi: true, laundry: true, }, ]; getAllHousingLocations(): HousingLocation[] { return this.housingLocationList; } getHousingLocationById(id: number): HousingLocation | undefined { return this.housingLocationList.find((housingLocation) => housingLocation.id === id); } submitApplication(firstName: string, lastName: string, email: string) { console.log( `Homes application received: firstName: ${firstName}, lastName: ${lastName}, email: ${email}.`, ); } }
{ "end_byte": 3183, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing.service.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/app.component.ts_0_671
import {Component} from '@angular/core'; import {HomeComponent} from './home/home.component'; import {RouterLink, RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', standalone: true, imports: [HomeComponent, RouterLink, RouterOutlet], template: ` <main> <a [routerLink]="['/']"> <header class="brand-name"> <img class="brand-logo" src="/assets/logo.svg" alt="logo" aria-hidden="true" /> </header> </a> <section class="content"> <router-outlet></router-outlet> </section> </main> `, styleUrls: ['./app.component.css'], }) export class AppComponent { title = 'homes'; }
{ "end_byte": 671, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/app.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/app.component.css_0_213
:host { --content-padding: 10px; } header { display: block; height: 60px; padding: var(--content-padding); box-shadow: 0px 5px 25px var(--shadow-color); } .content { padding: var(--content-padding); }
{ "end_byte": 213, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/app.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.component.ts_0_1531
import {Component, inject} from '@angular/core'; import {CommonModule} from '@angular/common'; import {HousingLocationComponent} from '../housing-location/housing-location.component'; import {HousingLocation} from '../housinglocation'; import {HousingService} from '../housing.service'; @Component({ selector: 'app-home', standalone: true, imports: [CommonModule, HousingLocationComponent], template: ` <section> <form> <input type="text" placeholder="Filter by city" #filter /> <button class="primary" type="button" (click)="filterResults(filter.value)">Search</button> </form> </section> <section class="results"> <app-housing-location *ngFor="let housingLocation of filteredLocationList" [housingLocation]="housingLocation" ></app-housing-location> </section> `, styleUrls: ['./home.component.css'], }) export class HomeComponent { housingLocationList: HousingLocation[] = []; housingService: HousingService = inject(HousingService); filteredLocationList: HousingLocation[] = []; constructor() { this.housingLocationList = this.housingService.getAllHousingLocations(); this.filteredLocationList = this.housingLocationList; } filterResults(text: string) { if (!text) { this.filteredLocationList = this.housingLocationList; return; } this.filteredLocationList = this.housingLocationList.filter((housingLocation) => housingLocation?.city.toLowerCase().includes(text.toLowerCase()), ); } }
{ "end_byte": 1531, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.component.css_0_746
.results { display: grid; column-gap: 14px; row-gap: 14px; grid-template-columns: repeat(auto-fill, minmax(400px, 400px)); margin-top: 50px; justify-content: space-around; } input[type="text"] { border: solid 1px var(--primary-color); padding: 10px; border-radius: 8px; margin-right: 4px; display: inline-block; width: 30%; } button { padding: 10px; border: solid 1px var(--primary-color); background: var(--primary-color); color: white; border-radius: 8px; } @media (min-width: 500px) and (max-width: 768px) { .results { grid-template-columns: repeat(2, 1fr); } input[type="text"] { width: 70%; } } @media (max-width: 499px) { .results { grid-template-columns: 1fr; } }
{ "end_byte": 746, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/home/home.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.component.css_0_583
.listing { background: var(--accent-color); border-radius: 30px; padding-bottom: 30px; } .listing-heading { color: var(--primary-color); padding: 10px 20px 0 20px; } .listing-photo { height: 250px; width: 100%; object-fit: cover; border-radius: 30px 30px 0 0; } .listing-location { padding: 10px 20px 20px 20px; } .listing-location::before { content: url("/assets/location-pin.svg") / ""; } section.listing a { padding-left: 20px; text-decoration: none; color: var(--primary-color); } section.listing a::after { content: "\203A"; margin-left: 5px; }
{ "end_byte": 583, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.component.ts_0_908
import {Component, Input} from '@angular/core'; import {CommonModule} from '@angular/common'; import {HousingLocation} from '../housinglocation'; import {RouterModule} from '@angular/router'; @Component({ selector: 'app-housing-location', standalone: true, imports: [CommonModule, RouterModule], template: ` <section class="listing"> <img class="listing-photo" [src]="housingLocation.photo" alt="Exterior photo of {{ housingLocation.name }}" crossorigin /> <h2 class="listing-heading">{{ housingLocation.name }}</h2> <p class="listing-location">{{ housingLocation.city }}, {{ housingLocation.state }}</p> <a [routerLink]="['/details', housingLocation.id]">Learn More</a> </section> `, styleUrls: ['./housing-location.component.css'], }) export class HousingLocationComponent { @Input() housingLocation!: HousingLocation; }
{ "end_byte": 908, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/housing-location/housing-location.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/details/details.component.ts_0_2660
import {Component, inject} from '@angular/core'; import {CommonModule} from '@angular/common'; import {ActivatedRoute} from '@angular/router'; import {HousingService} from '../housing.service'; import {HousingLocation} from '../housinglocation'; import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms'; @Component({ selector: 'app-details', standalone: true, imports: [CommonModule, ReactiveFormsModule], template: ` <article> <img class="listing-photo" [src]="housingLocation?.photo" alt="Exterior photo of {{ housingLocation?.name }}" crossorigin /> <section class="listing-description"> <h2 class="listing-heading">{{ housingLocation?.name }}</h2> <p class="listing-location">{{ housingLocation?.city }}, {{ housingLocation?.state }}</p> </section> <section class="listing-features"> <h2 class="section-heading">About this housing location</h2> <ul> <li>Units available: {{ housingLocation?.availableUnits }}</li> <li>Does this location have wifi: {{ housingLocation?.wifi }}</li> <li>Does this location have laundry: {{ housingLocation?.laundry }}</li> </ul> </section> <section class="listing-apply"> <h2 class="section-heading">Apply now to live here</h2> <form [formGroup]="applyForm" (submit)="submitApplication()"> <label for="first-name">First Name</label> <input id="first-name" type="text" formControlName="firstName" /> <label for="last-name">Last Name</label> <input id="last-name" type="text" formControlName="lastName" /> <label for="email">Email</label> <input id="email" type="email" formControlName="email" /> <button type="submit" class="primary">Apply now</button> </form> </section> </article> `, styleUrls: ['./details.component.css'], }) export class DetailsComponent { route: ActivatedRoute = inject(ActivatedRoute); housingService = inject(HousingService); housingLocation: HousingLocation | undefined; applyForm = new FormGroup({ firstName: new FormControl(''), lastName: new FormControl(''), email: new FormControl(''), }); constructor() { const housingLocationId = parseInt(this.route.snapshot.params['id'], 10); this.housingLocation = this.housingService.getHousingLocationById(housingLocationId); } submitApplication() { this.housingService.submitApplication( this.applyForm.value.firstName ?? '', this.applyForm.value.lastName ?? '', this.applyForm.value.email ?? '', ); } }
{ "end_byte": 2660, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/details/details.component.ts" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/app/details/details.component.css_0_1075
.listing-photo { height: 600px; width: 50%; object-fit: cover; border-radius: 30px; float: right; } .listing-heading { font-size: 48pt; font-weight: bold; margin-bottom: 15px; } .listing-location::before { content: url('/assets/location-pin.svg') / ''; } .listing-location { font-size: 24pt; margin-bottom: 15px; } .listing-features > .section-heading { color: var(--secondary-color); font-size: 24pt; margin-bottom: 15px; } .listing-features { margin-bottom: 20px; } .listing-features li { font-size: 14pt; } li { list-style-type: none; } .listing-apply .section-heading { font-size: 18pt; margin-bottom: 15px; } label, input { display: block; } label { color: var(--secondary-color); font-weight: bold; text-transform: uppercase; font-size: 12pt; } input { font-size: 16pt; margin-bottom: 15px; padding: 10px; width: 400px; border-top: none; border-right: none; border-left: none; border-bottom: solid .3px; } @media (max-width: 1024px) { .listing-photo { width: 100%; height: 400px; } }
{ "end_byte": 1075, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/app/details/details.component.css" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/assets/location-pin.svg_0_502
<?xml version="1.0" encoding="UTF-8"?> <svg width="20pt" height="20pt" version="1.1" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> <path d="m50 11.602c-15.398 0-27.898 12.5-27.898 27.898 0 5 1.3008 9.6992 3.6016 13.801l2.8984 4.1992 21.398 30.898 21.801-31.398 2.1992-3.1992c2.5-4.1992 3.8984-9 3.8984-14.199 0-15.5-12.5-28-27.898-28zm0 35.598c-4.1992 0-7.6992-3.3984-7.6992-7.6992s3.3984-7.6992 7.6992-7.6992 7.6992 3.3984 7.6992 7.6992-3.5 7.6992-7.6992 7.6992z" fill="#605cc8"/> </svg>
{ "end_byte": 502, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/assets/location-pin.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg_0_2207
<svg width="151" height="44" viewBox="0 0 151 44" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M6.15532 33.2946C5.25369 33.2946 4.58006 32.5707 4.58006 31.6701V24.0152C4.58006 19.5469 4.35206 20.6276 7.59585 17.4236C21.7317 4.06732 16.2425 4.24744 29.6149 18.054C32.0434 20.7627 31.9985 19.4534 31.9985 23.8316V31.6667C31.9985 32.5707 31.28 33.2912 30.3749 33.2912H6.15532V33.2946Z" fill="#605DC8"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M30.896 35.1547L5.73676 35.2586C4.80059 35.2621 3.75042 35.8232 3.37388 36.5229L2.90061 37.4027L0.537726 41.7878L0.140457 42.529C-0.236085 43.2253 0.164639 43.7829 1.10081 43.7795L26.26 43.6756C27.1962 43.6721 28.2464 43.111 28.6229 42.4113L29.0962 41.5315L31.4591 37.1463L31.8563 36.4051C32.2329 35.7089 31.8321 35.1512 30.896 35.1547Z" fill="#605DC8"/> <path d="M2.54861 18.7156C2.23079 18.7156 1.90952 18.629 1.6228 18.4454C0.821352 17.9363 0.5899 16.859 1.09771 16.0554C1.46389 15.4701 2.70061 14.2231 5.50912 11.4659L6.39693 10.5931C8.73218 8.38318 10.5147 6.56817 11.9449 5.10646C15.1679 1.81587 16.7985 0.153263 18.9023 0.222538C20.9888 0.277958 22.4362 1.92325 25.3138 5.19651C26.7267 6.8037 28.4816 8.8023 30.8514 11.2477C30.8652 11.265 30.8825 11.2789 30.8963 11.2962C31.228 11.6634 31.715 12.2003 32.2401 12.7752C33.9743 14.6734 34.8206 15.6086 35.0763 15.9688C35.629 16.7413 35.4494 17.8185 34.679 18.3727C33.9087 18.9234 32.8343 18.7468 32.2816 17.9744C32.0639 17.6869 30.5889 16.0693 29.708 15.1064C29.1863 14.5348 28.6993 14.0014 28.3642 13.6308C25.9495 11.1369 24.1704 9.11057 22.7368 7.4826C21.0233 5.5325 19.4032 3.68977 18.809 3.67245H18.8021C18.1699 3.67245 16.3356 5.54289 14.3976 7.52417C12.9467 9.00666 11.14 10.8494 8.78054 13.0766L7.91001 13.9321C6.74929 15.0717 4.33804 17.4375 3.97877 17.9293C3.65405 18.4454 3.10824 18.7225 2.54515 18.7225L2.54861 18.7156Z" fill="#605DC8"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M22.0976 33.2115V26.0588C22.0976 25.4665 21.6174 24.985 21.0267 24.985H15.1955C14.6047 24.985 14.1246 25.4665 14.1246 26.0588V33.2115C14.1246 33.2704 14.1142 33.3293 14.0969 33.3847H22.1252C22.1079 33.3293 22.0976 33.2739 22.0976 33.2115Z" fill="white"/>
{ "end_byte": 2207, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg_2208_5628
<path d="M58.9784 10.0512V32.2205H54.5319V22.7874H45.0353V32.2205H40.5887V10.0512H45.0353V19.1666H54.5319V10.0512H58.9784ZM70.8506 32.5063C69.1567 32.5063 67.6322 32.1358 66.277 31.3947C64.9219 30.6324 63.8526 29.5631 63.0692 28.1868C62.3069 26.8105 61.9258 25.2224 61.9258 23.4226C61.9258 21.6228 62.3175 20.0348 63.1009 18.6585C63.9055 17.2821 64.996 16.2234 66.3723 15.4823C67.7486 14.7201 69.2838 14.3389 70.9777 14.3389C72.6716 14.3389 74.2067 14.7201 75.5831 15.4823C76.9594 16.2234 78.0393 17.2821 78.8227 18.6585C79.6273 20.0348 80.0296 21.6228 80.0296 23.4226C80.0296 25.2224 79.6167 26.8105 78.7909 28.1868C77.9863 29.5631 76.8853 30.6324 75.4878 31.3947C74.1115 32.1358 72.5657 32.5063 70.8506 32.5063ZM70.8506 28.6315C71.6553 28.6315 72.4069 28.4409 73.1057 28.0597C73.8256 27.6574 74.3973 27.0646 74.8208 26.2811C75.2443 25.4977 75.456 24.5449 75.456 23.4226C75.456 21.7499 75.0114 20.4688 74.122 19.5795C73.2539 18.669 72.1846 18.2138 70.9142 18.2138C69.6437 18.2138 68.5744 18.669 67.7063 19.5795C66.8593 20.4688 66.4358 21.7499 66.4358 23.4226C66.4358 25.0954 66.8487 26.387 67.6745 27.2975C68.5215 28.1868 69.5802 28.6315 70.8506 28.6315ZM104.825 14.3707C106.985 14.3707 108.721 15.0377 110.034 16.3717C111.368 17.6844 112.035 19.5266 112.035 21.8981V32.2205H107.589V22.5016C107.589 21.1252 107.239 20.0771 106.54 19.3572C105.842 18.6161 104.889 18.2456 103.682 18.2456C102.475 18.2456 101.512 18.6161 100.792 19.3572C100.093 20.0771 99.7436 21.1252 99.7436 22.5016V32.2205H95.297V22.5016C95.297 21.1252 94.9477 20.0771 94.2489 19.3572C93.5502 18.6161 92.5974 18.2456 91.3904 18.2456C90.1623 18.2456 89.1883 18.6161 88.4684 19.3572C87.7697 20.0771 87.4203 21.1252 87.4203 22.5016V32.2205H82.9737V14.6248H87.4203V16.7528C87.992 16.0117 88.7225 15.4294 89.6118 15.0059C90.5223 14.5824 91.5175 14.3707 92.5974 14.3707C93.9737 14.3707 95.2018 14.6671 96.2816 15.26C97.3615 15.8317 98.1979 16.6575 98.7908 17.7374C99.3625 16.721 100.188 15.9058 101.268 15.2918C102.369 14.6777 103.555 14.3707 104.825 14.3707ZM132.294 23.0415C132.294 23.6767 132.252 24.2484 132.167 24.7566H119.304C119.41 26.027 119.854 27.0222 120.638 27.7421C121.421 28.4621 122.385 28.822 123.528 28.822C125.18 28.822 126.355 28.1127 127.053 26.694H131.849C131.341 28.3879 130.367 29.7854 128.927 30.8865C127.488 31.9664 125.72 32.5063 123.623 32.5063C121.929 32.5063 120.405 32.1358 119.05 31.3947C117.716 30.6324 116.668 29.5631 115.905 28.1868C115.164 26.8105 114.794 25.2224 114.794 23.4226C114.794 21.6017 115.164 20.003 115.905 18.6267C116.646 17.2504 117.684 16.1917 119.018 15.4506C120.352 14.7095 121.887 14.3389 123.623 14.3389C125.296 14.3389 126.789 14.6989 128.102 15.4188C129.436 16.1387 130.462 17.1657 131.182 18.4996C131.924 19.8124 132.294 21.3264 132.294 23.0415ZM127.689 21.771C127.668 20.6276 127.255 19.7172 126.45 19.0396C125.645 18.3408 124.661 17.9915 123.496 17.9915C122.395 17.9915 121.464 18.3303 120.701 19.0078C119.96 19.6642 119.505 20.5853 119.336 21.771H127.689ZM141.955 32.5063C140.516 32.5063 139.224 32.2522 138.081 31.744C136.937 31.2147 136.027 30.5054 135.349 29.616C134.693 28.7267 134.333 27.7421 134.269 26.6623H138.748C138.832 27.3398 139.16 27.9009 139.732 28.3456C140.325 28.7903 141.055 29.0126 141.924 29.0126C142.771 29.0126 143.427 28.8432 143.893 28.5044C144.38 28.1656 144.623 27.7316 144.623 27.2022C144.623 26.6305 144.327 26.207 143.734 25.9318C143.162 25.6353 142.241 25.3177 140.971
{ "end_byte": 5628, "start_byte": 2208, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg_5629_6611
24.9789C139.658 24.6613 138.578 24.3331 137.731 23.9943C136.905 23.6555 136.185 23.1368 135.571 22.438C134.979 21.7393 134.682 20.797 134.682 19.6113C134.682 18.6373 134.957 17.748 135.508 16.9434C136.08 16.1387 136.884 15.5035 137.922 15.0377C138.98 14.5719 140.219 14.3389 141.638 14.3389C143.734 14.3389 145.407 14.8683 146.656 15.927C147.905 16.9645 148.593 18.3726 148.721 20.1512H144.465C144.401 19.4525 144.105 18.902 143.575 18.4996C143.067 18.0762 142.379 17.8644 141.511 17.8644C140.706 17.8644 140.081 18.0126 139.637 18.3091C139.213 18.6055 139.002 19.0184 139.002 19.5478C139.002 20.1406 139.298 20.5959 139.891 20.9135C140.484 21.2099 141.405 21.517 142.654 21.8346C143.925 22.1522 144.973 22.4804 145.798 22.8192C146.624 23.1579 147.334 23.6873 147.926 24.4072C148.541 25.106 148.858 26.0376 148.879 27.2022C148.879 28.2186 148.593 29.129 148.022 29.9337C147.471 30.7383 146.667 31.3735 145.608 31.8393C144.57 32.284 143.353 32.5063 141.955 32.5063Z" fill="#605DC8"/>
{ "end_byte": 6611, "start_byte": 5629, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg" }
angular/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg_6612_6619
</svg>
{ "end_byte": 6619, "start_byte": 6612, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/14-http/src/assets/logo.svg" }
angular/adev/src/content/tutorials/learn-angular/BUILD.bazel_0_407
load("//adev/shared-docs:index.bzl", "generate_guides", "generate_tutorial") package(default_visibility = ["//adev:__subpackages__"]) generate_guides( name = "learn-angular-guides", srcs = glob(["**/*.md"]), ) filegroup( name = "files", srcs = glob( ["**/*"], exclude = ["**/*.md"], ), ) generate_tutorial( name = "learn-angular", tutorial_srcs = ":files", )
{ "end_byte": 407, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/BUILD.bazel" }
angular/adev/src/content/tutorials/learn-angular/intro/README.md_0_476
# Welcome to the Angular tutorial This interactive tutorial will teach you the basic building blocks to start building great apps with Angular. ## How to use this tutorial You'll need to have basic familiarity with HTML, CSS and JavaScript to understand Angular. Each step represents a concept in Angular. You can do one, or all of them. If you get stuck, click "Reveal answer" at the top. Alright, let's [get started](/tutorials/learn-angular/1-components-in-angular).
{ "end_byte": 476, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/intro/README.md" }
angular/adev/src/content/tutorials/learn-angular/intro/src/app/app.component.ts_0_174
import {Component} from '@angular/core'; @Component({ selector: 'app-root', template: ` Welcome to Angular! `, standalone: true, }) export class AppComponent {}
{ "end_byte": 174, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/intro/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/common/idx/dev.nix_0_1086
# To learn more about how to use Nix to configure your environment # see: https://developers.google.com/idx/guides/customize-idx-env { pkgs, ... }: { # Which nixpkgs channel to use. channel = "stable-23.11"; # or "unstable" # Use https://search.nixos.org/packages to find packages packages = [ pkgs.nodejs_18 ]; # Sets environment variables in the workspace env = {}; idx = { # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" extensions = [ "angular.ng-template" ]; workspace = { # Runs when a workspace is first created with this \`dev.nix\` file onCreate = { npm-install = "npm install --no-audit --prefer-offline"; }; # To run something each time the environment is rebuilt, use the \`onStart\` hook }; # Enable previews and customize configuration previews = { enable = true; previews = { web = { command = ["npm" "run" "start" "--" "--port" "$PORT" "--host" "0.0.0.0"]; manager = "web"; }; }; }; }; }
{ "end_byte": 1086, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/common/idx/dev.nix" }
angular/adev/src/content/tutorials/learn-angular/steps/4-control-flow-if/README.md_0_1915
# Control Flow in Components - `@if` Deciding what to display on the screen for a user is a common task in application development. Many times, the decision is made programmatically using conditions. To express conditional displays in templates, Angular uses the `@if` template syntax. In this activity, you'll learn how to use conditionals in templates. <hr/> The syntax that enables the conditional display of elements in a template is `@if`. Here's an example of how to use the `@if` syntax in a component: ```angular-ts @Component({ ... template: ` @if (isLoggedIn) { <p>Welcome back, Friend!</p> } `, }) class AppComponent { isLoggedIn = true; } ``` Two things to take note of: - There is an `@` prefix for the `if` because it is a special type of syntax called [Angular template syntax](guide/templates) - For applications using v16 and older please refer to the [Angular documentation for NgIf](guide/directives/structural-directives) for more information. <docs-workflow> <docs-step title="Create a property called `isServerRunning`"> In the `AppComponent` class, add a `boolean` property called `isServerRunning`, set the initial value to `true`. </docs-step> <docs-step title="Use `@if` in the template"> Update the template to display the message `Yes, the server is running` if the value of `isServerRunning` is `true`. </docs-step> <docs-step title="Use `@else` in the template"> Now Angular supports native template syntax for defining the else case with the `@else` syntax. Update the template to display the message `No, the server is not running` as the else case. Here's an example: ```angular-ts template: ` @if (isServerRunning) { ... } @else { ... } `; ``` Add your code to fill in the missing markup. </docs-step> </docs-workflow> This type of functionality is called conditional control flow. Next you'll learn how to repeat items in a template.
{ "end_byte": 1915, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/4-control-flow-if/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/4-control-flow-if/answer/src/app/app.component.ts_0_316
import {Component} from '@angular/core'; @Component({ selector: 'app-root', template: ` @if (isServerRunning) { <span>Yes, the server is running</span> } @else { <span>No, the server is not running</span> } `, standalone: true, }) export class AppComponent { isServerRunning = true; }
{ "end_byte": 316, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/4-control-flow-if/answer/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/4-control-flow-if/src/app/app.component.ts_0_230
import {Component} from '@angular/core'; @Component({ selector: 'app-root', template: ` <span>Yes, the server is running</span> `, standalone: true, }) export class AppComponent { // add the boolean property here }
{ "end_byte": 230, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/4-control-flow-if/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/README.md_0_1688
# Use RouterLink for Navigation In the app's current state, the entire page refreshes when we click on an internal link that exists within the app. While this may not seem significant with a small app, this can have performance implications for larger pages with more content where users have to redownload assets and run calculations again. In this activity, you'll learn how to leverage the `RouterLink` directive to make the most use of Angular Router. <hr> <docs-workflow> <docs-step title="Import `RouterLink` directive"> In `app.component.ts` add the `RouterLink` directive import to the existing import statement from `@angular/router` and add it to the `imports` array of your component decorator. ```ts ... import { RouterLink, RouterOutlet } from '@angular/router'; @Component({ standalone: true, imports: [RouterLink, RouterOutlet], ... }) ``` </docs-step> <docs-step title="Add a `routerLink` to template"> To use the `RouterLink` directive, replace the `href` attributes with `routerLink`. Update the template with this change. ```angular-ts import { RouterLink, RouterOutlet } from '@angular/router'; @Component({ ... standalone: true, template: ` ... <a routerLink="/">Home</a> <a routerLink="/user">User</a> ... `, imports: [RouterLink, RouterOutlet], }) ``` </docs-step> </docs-workflow> When you click on the links in the navigation now, you should not see any blinking and only the content of the page itself (i.e., `router-outlet`) being changed ๐ŸŽ‰ Great job learning about routing with Angular. This is just the surface of the `Router` API, to learn more check out the [Angular Router Documentation](guide/routing).
{ "end_byte": 1688, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/main.ts_0_241
import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {appConfig} from './app/app.config'; bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
{ "end_byte": 241, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/main.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/app.routes.ts_0_349
import {Routes} from '@angular/router'; import {HomeComponent} from './home/home.component'; import {UserComponent} from './user/user.component'; export const routes: Routes = [ { path: '', title: 'App Home Page', component: HomeComponent, }, { path: 'user', title: 'App User Page', component: UserComponent, }, ];
{ "end_byte": 349, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/app.routes.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/app.component.ts_0_368
import {Component} from '@angular/core'; import {RouterOutlet, RouterLink} from '@angular/router'; @Component({ selector: 'app-root', template: ` <nav> <a routerLink="/">Home</a> | <a routerLink="/user">User</a> </nav> <router-outlet /> `, standalone: true, imports: [RouterOutlet, RouterLink], }) export class AppComponent {}
{ "end_byte": 368, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/app.config.ts_0_222
import {ApplicationConfig} from '@angular/core'; import {provideRouter} from '@angular/router'; import {routes} from './app.routes'; export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)], };
{ "end_byte": 222, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/app.config.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/home/home.component.ts_0_176
import {Component} from '@angular/core'; @Component({ selector: 'app-home', template: ` <div>Home Page</div> `, standalone: true, }) export class HomeComponent {}
{ "end_byte": 176, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/home/home.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/user/user.component.ts_0_218
import {Component} from '@angular/core'; @Component({ selector: 'app-user', template: ` <div>Username: {{ username }}</div> `, standalone: true, }) export class UserComponent { username = 'youngTech'; }
{ "end_byte": 218, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/answer/src/app/user/user.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/main.ts_0_241
import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {appConfig} from './app/app.config'; bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
{ "end_byte": 241, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/main.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/app.routes.ts_0_349
import {Routes} from '@angular/router'; import {HomeComponent} from './home/home.component'; import {UserComponent} from './user/user.component'; export const routes: Routes = [ { path: '', title: 'App Home Page', component: HomeComponent, }, { path: 'user', title: 'App User Page', component: UserComponent, }, ];
{ "end_byte": 349, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/app.routes.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/app.component.ts_0_332
import {Component} from '@angular/core'; import {RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', template: ` <nav> <a href="/">Home</a> | <a href="/user">User</a> </nav> <router-outlet /> `, standalone: true, imports: [RouterOutlet], }) export class AppComponent {}
{ "end_byte": 332, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/app.config.ts_0_222
import {ApplicationConfig} from '@angular/core'; import {provideRouter} from '@angular/router'; import {routes} from './app.routes'; export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)], };
{ "end_byte": 222, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/app.config.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/home/home.component.ts_0_176
import {Component} from '@angular/core'; @Component({ selector: 'app-home', template: ` <div>Home Page</div> `, standalone: true, }) export class HomeComponent {}
{ "end_byte": 176, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/home/home.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/user/user.component.ts_0_218
import {Component} from '@angular/core'; @Component({ selector: 'app-user', template: ` <div>Username: {{ username }}</div> `, standalone: true, }) export class UserComponent { username = 'youngTech'; }
{ "end_byte": 218, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/14-routerLink/src/app/user/user.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/README.md_0_2169
# Routing Overview For most apps, there comes a point where the app requires more than a single page. When that time inevitably comes, routing becomes a big part of the performance story for users. In this activity, you'll learn how to setup and configure your app to use Angular Router. <hr> <docs-workflow> <docs-step title="Create an app.routes.ts file"> Inside `app.routes.ts`, make the following changes: 1. Import `Routes` from the `@angular/router` package. 1. Export a constant called `routes` of type `Routes`, assign it `[]` as the value. ```ts import {Routes} from '@angular/router'; export const routes: Routes = []; ``` </docs-step> <docs-step title="Add routing to provider"> In `app.config.ts`, configure the app to Angular Router with the following steps: 1. Import the `provideRouter` function from `@angular/router`. 1. Import `routes` from the `./app.routes.ts`. 1. Call the `provideRouter` function with `routes` passed in as an argument in the `providers` array. <docs-code language="ts" highlight="[2,3,6]"> import {ApplicationConfig} from '@angular/core'; import {provideRouter} from '@angular/router'; import {routes} from './app.routes'; export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)], }; </docs-code> </docs-step> <docs-step title="Import `RouterOutlet` in the component"> Finally, to make sure your app is ready to use the Angular Router, you need to tell the app where you expect the router to display the desired content. Accomplish that by using the `RouterOutlet` directive from `@angular/router`. Update the template for `AppComponent` by adding `<router-outlet />` <docs-code language="angular-ts" highlight="[11]"> import {RouterOutlet} from '@angular/router'; @Component({ ... template: ` <nav> <a href="/">Home</a> | <a href="/user">User</a> </nav> <router-outlet /> `, standalone: true, imports: [RouterOutlet], }) export class AppComponent {} </docs-code> </docs-step> </docs-workflow> Your app is now setup to use Angular Router. Nice work! ๐Ÿ™Œ Keep the momentum going to learn the next step of defining the routes for our app.
{ "end_byte": 2169, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/main.ts_0_241
import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {appConfig} from './app/app.config'; bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
{ "end_byte": 241, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/main.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/app.routes.ts_0_75
import {Routes} from '@angular/router'; export const routes: Routes = [];
{ "end_byte": 75, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/app.routes.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/app.component.ts_0_332
import {Component} from '@angular/core'; import {RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', template: ` <nav> <a href="/">Home</a> | <a href="/user">User</a> </nav> <router-outlet /> `, standalone: true, imports: [RouterOutlet], }) export class AppComponent {}
{ "end_byte": 332, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/app.config.ts_0_222
import {ApplicationConfig} from '@angular/core'; import {provideRouter} from '@angular/router'; import {routes} from './app.routes'; export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)], };
{ "end_byte": 222, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/app.config.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/home/home.component.ts_0_176
import {Component} from '@angular/core'; @Component({ selector: 'app-home', template: ` <div>Home Page</div> `, standalone: true, }) export class HomeComponent {}
{ "end_byte": 176, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/home/home.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/user/user.component.ts_0_218
import {Component} from '@angular/core'; @Component({ selector: 'app-user', template: ` <div>Username: {{ username }}</div> `, standalone: true, }) export class UserComponent { username = 'youngTech'; }
{ "end_byte": 218, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/answer/src/app/user/user.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/main.ts_0_241
import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {appConfig} from './app/app.config'; bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
{ "end_byte": 241, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/main.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/app.component.ts_0_310
import {Component} from '@angular/core'; import {RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', template: ` <nav> <a href="/">Home</a> | <a href="/user">User</a> </nav> `, standalone: true, imports: [RouterOutlet], }) export class AppComponent {}
{ "end_byte": 310, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/app.config.ts_0_116
import {ApplicationConfig} from '@angular/core'; export const appConfig: ApplicationConfig = { providers: [], };
{ "end_byte": 116, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/app.config.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/home/home.component.ts_0_176
import {Component} from '@angular/core'; @Component({ selector: 'app-home', template: ` <div>Home Page</div> `, standalone: true, }) export class HomeComponent {}
{ "end_byte": 176, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/home/home.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/user/user.component.ts_0_218
import {Component} from '@angular/core'; @Component({ selector: 'app-user', template: ` <div>Username: {{ username }}</div> `, standalone: true, }) export class UserComponent { username = 'youngTech'; }
{ "end_byte": 218, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/12-enable-routing/src/app/user/user.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/README.md_0_6035
# Deferrable Views Sometimes in app development, you end up with a lot of components that you need to reference in your app, but some of those don't need to be loaded right away for various reasons. Maybe they are below the visible fold or are heavy components that aren't interacted with until later. In that case, we can load some of those resources later with deferrable views. In this activity, you'll learn how to use deferrable views to defer load a section of your component template. <hr> <docs-workflow> <docs-step title="Add a `@defer` block around the comments component"> In your app, the blog post page has a comment component after the post details. Wrap the comment component with a `@defer` block to defer load it. ```angular-html @defer { <comments /> } ``` The code above is an example of how to use a basic `@defer` block. By default `@defer` will load the `comments` component when the browser is idle. </docs-step> <docs-step title="Add a placeholder"> Add a `@placeholder` block to the `@defer` block. The `@placeholder` block is where you put html that will show before the deferred loading starts. The content in `@placeholder` blocks is eagerly loaded. <docs-code language="angular-html" highlight="[3,4,5]"> @defer { <comments /> } @placeholder { <p>Future comments</p> } </docs-code> </docs-step> <docs-step title="Add a loading block"> Add a `@loading` block to the `@defer` block. The `@loading` block is where you put html that will show _while_ the deferred content is actively being fetched, but hasn't finished yet. The content in `@loading` blocks is eagerly loaded. <docs-code language="angular-html" highlight="[5,6,7]"> @defer { <comments /> } @placeholder { <p>Future comments</p> } @loading { <p>Loading comments...</p> } </docs-code> </docs-step> <docs-step title="Add a minimum duration"> Both `@placeholder` and `@loading` sections have optional parameters to prevent flickering from occurring when loading happens quickly. `@placeholder` has `minimum` and `@loading` has `minimum` and `after`. Add a `minimum` duration to the `@loading` block so it will be rendered for at least 2 seconds. <docs-code language="angular-html" highlight="[5]"> @defer { <comments /> } @placeholder { <p>Future comments</p> } @loading (minimum 2s) { <p>Loading comments...</p> } </docs-code> </docs-step> <docs-step title="Add a viewport trigger"> Deferrable views have a number of trigger options. Add a viewport trigger so the content will defer load once it enters the viewport. <docs-code language="angular-html" highlight="[1]"> @defer (on viewport) { <comments /> } </docs-code> </docs-step> <docs-step title="Add content"> A viewport trigger is best used when you're deferring content that's far enough down the page that it needs to be scrolled to see. So let's add some content to our blog post. You can either write your own, or you can copy the content below and put it inside the `<article>` element. <docs-code language="html" highlight="[1]"> <article> <p>Angular is my favorite framework, and this is why. Angular has the coolest deferrable view feature that makes defer loading content the easiest and most ergonomic it could possibly be. The Angular community is also filled with amazing contributors and experts that create excellent content. The community is welcoming and friendly, and it really is the best community out there.</p> <p>I can't express enough how much I enjoy working with Angular. It offers the best developer experience I've ever had. I love that the Angular team puts their developers first and takes care to make us very happy. They genuinely want Angular to be the best framework it can be, and they're doing such an amazing job at it, too. This statement comes from my heart and is not at all copied and pasted. In fact, I think I'll say these exact same things again a few times.</p> <p>Angular is my favorite framework, and this is why. Angular has the coolest deferrable view feature that makes defer loading content the easiest and most ergonomic it could possibly be. The Angular community is also filled with amazing contributors and experts that create excellent content. The community is welcoming and friendly, and it really is the best community out there.</p> <p>I can't express enough how much I enjoy working with Angular. It offers the best developer experience I've ever had. I love that the Angular team puts their developers first and takes care to make us very happy. They genuinely want Angular to be the best framework it can be, and they're doing such an amazing job at it, too. This statement comes from my heart and is not at all copied and pasted. In fact, I think I'll say these exact same things again a few times.</p> <p>Angular is my favorite framework, and this is why. Angular has the coolest deferrable view feature that makes defer loading content the easiest and most ergonomic it could possibly be. The Angular community is also filled with amazing contributors and experts that create excellent content. The community is welcoming and friendly, and it really is the best community out there.</p> <p>I can't express enough how much I enjoy working with Angular. It offers the best developer experience I've ever had. I love that the Angular team puts their developers first and takes care to make us very happy. They genuinely want Angular to be the best framework it can be, and they're doing such an amazing job at it, too. This statement comes from my heart and is not at all copied and pasted.</p> </article> </docs-code> Once you've added this code, now scroll down to see the deferred content load once you scroll it into the viewport. </docs-step> </docs-workflow> In the activity, you've learned how to use deferrable views in your applications. Great work. ๐Ÿ™Œ There's even more you can do with them, like different triggers, prefetching, and `@error` blocks. If you would like to learn more, check out the [documentation for Deferrable views](guide/defer).
{ "end_byte": 6035, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/main.ts_0_241
import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {appConfig} from './app/app.config'; bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
{ "end_byte": 241, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/main.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/app/comments.component.ts_0_320
import {Component} from '@angular/core'; @Component({ selector: 'comments', template: ` <ul> <li>Building for the web is fantastic!</li> <li>The new template syntax is great</li> <li>I agree with the other comments!</li> </ul> `, standalone: true, }) export class CommentsComponent {}
{ "end_byte": 320, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/app/comments.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/app/app.component.ts_0_3445
import {Component} from '@angular/core'; import {CommentsComponent} from './comments.component'; @Component({ selector: 'app-root', template: ` <div> <h1>How I feel about Angular</h1> <article> <p> Angular is my favorite framework, and this is why. Angular has the coolest deferrable view feature that makes defer loading content the easiest and most ergonomic it could possibly be. The Angular community is also filled with amazing contributors and experts that create excellent content. The community is welcoming and friendly, and it really is the best community out there. </p> <p> I can't express enough how much I enjoy working with Angular. It offers the best developer experience I've ever had. I love that the Angular team puts their developers first and takes care to make us very happy. They genuinely want Angular to be the best framework it can be, and they're doing such an amazing job at it, too. This statement comes from my heart and is not at all copied and pasted. In fact, I think I'll say these exact same things again a few times. </p> <p> Angular is my favorite framework, and this is why. Angular has the coolest deferrable view feature that makes defer loading content the easiest and most ergonomic it could possibly be. The Angular community is also filled with amazing contributors and experts that create excellent content. The community is welcoming and friendly, and it really is the best community out there. </p> <p> I can't express enough how much I enjoy working with Angular. It offers the best developer experience I've ever had. I love that the Angular team puts their developers first and takes care to make us very happy. They genuinely want Angular to be the best framework it can be, and they're doing such an amazing job at it, too. This statement comes from my heart and is not at all copied and pasted. In fact, I think I'll say these exact same things again a few times. </p> <p> Angular is my favorite framework, and this is why. Angular has the coolest deferrable view feature that makes defer loading content the easiest and most ergonomic it could possibly be. The Angular community is also filled with amazing contributors and experts that create excellent content. The community is welcoming and friendly, and it really is the best community out there. </p> <p> I can't express enough how much I enjoy working with Angular. It offers the best developer experience I've ever had. I love that the Angular team puts their developers first and takes care to make us very happy. They genuinely want Angular to be the best framework it can be, and they're doing such an amazing job at it, too. This statement comes from my heart and is not at all copied and pasted. </p> </article> @defer (on viewport) { <comments /> } @placeholder { <p>Future comments</p> } @loading (minimum 2s) { <p>Loading comments...</p> } </div> `, standalone: true, imports: [CommentsComponent], }) export class AppComponent {}
{ "end_byte": 3445, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/app/app.config.ts_0_116
import {ApplicationConfig} from '@angular/core'; export const appConfig: ApplicationConfig = { providers: [], };
{ "end_byte": 116, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/answer/src/app/app.config.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/main.ts_0_241
import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {appConfig} from './app/app.config'; bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
{ "end_byte": 241, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/main.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/app/comments.component.ts_0_320
import {Component} from '@angular/core'; @Component({ selector: 'comments', template: ` <ul> <li>Building for the web is fantastic!</li> <li>The new template syntax is great</li> <li>I agree with the other comments!</li> </ul> `, standalone: true, }) export class CommentsComponent {}
{ "end_byte": 320, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/app/comments.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/app/app.component.ts_0_344
import {Component} from '@angular/core'; import {CommentsComponent} from './comments.component'; @Component({ selector: 'app-root', template: ` <div> <h1>How I feel about Angular</h1> <article></article> <comments /> </div> `, standalone: true, imports: [CommentsComponent], }) export class AppComponent {}
{ "end_byte": 344, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/app/app.config.ts_0_116
import {ApplicationConfig} from '@angular/core'; export const appConfig: ApplicationConfig = { providers: [], };
{ "end_byte": 116, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/10-deferrable-views/src/app/app.config.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/25-next-steps/README.md_0_834
# Ready to explore more of Angular? You can also learn more in our [guides](overview) and [reference](api), or `ng new`. <docs-card-container> <docs-card title="What is Angular?" href="overview"> Angular is the web development framework for building modern apps! </docs-card> <docs-card title="Angular's Roadmap" href="roadmap"> Read about Angular's open source roadmap including current, future and accomplished projects. </docs-card> <docs-card title="Playground" href="playground" link="Start playing"> Play with Angular in your browser! </docs-card> <docs-card title="Angular YouTube Course" href="https://youtube.com/playlist?list=PL1w1q3fL4pmj9k1FrJ3Pe91EPub2_h4jF" link="Start learning"> Check out the official Angular YouTube channel for videos, courses and more! </docs-card> </docs-card-container>
{ "end_byte": 834, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/25-next-steps/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/README.md_0_1928
# Inject-based dependency injection Creating an injectable service is the first part of the dependency injection (DI) system in Angular. How do you inject a service into a component? Angular has a convenient function called `inject()` that can be used in the proper context. Note: Injection contexts are beyond the scope of this tutorial, but you can find more information in the [Angular Docs](guide/di/dependency-injection-context) if you would like to learn more. In this activity, you'll learn how to inject a service and use it in a component. <hr> It is often helpful to initialize class properties with values provided by the DI system. Here's an example: <docs-code language="ts" highlight="[3]"> @Component({...}) class PetCareDashboardComponent { petRosterService = inject(PetRosterService); } </docs-code> <docs-workflow> <docs-step title="Inject the `CarService`"> In `app.component.ts`, using the `inject()` function inject the `CarService` and assign it to a property called `carService` Note: Notice the difference between the property `carService` and the class `CarService`. </docs-step> <docs-step title="Use the `carService` instance"> Calling `inject(CarService)` gave you an instance of the `CarService` that you can use in your application, stored in the `carService` property. In the `constructor` function of the `AppComponent`, add the following implementation: ```ts constructor() { this.display = this.carService.getCars().join(' โญ๏ธ '); } ``` </docs-step> <docs-step title="Update the `AppComponent` template"> Update the component template in `app.component.ts` with the following code: ```ts template: `<p>Car Listing: {{ display }}</p>`, ``` </docs-step> </docs-workflow> You've just injected your first service into a component - fantastic effort. Before you finish this section on DI, you'll learn an alternative syntax to inject resources into your components.
{ "end_byte": 1928, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/answer/src/app/car.service.ts_0_277
import {Injectable} from '@angular/core'; @Injectable({ providedIn: 'root', }) export class CarService { cars = ['Sunflower GT', 'Flexus Sport', 'Sprout Mach One']; getCars(): string[] { return this.cars; } getCar(id: number) { return this.cars[id]; } }
{ "end_byte": 277, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/answer/src/app/car.service.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/answer/src/app/app.component.ts_0_376
import {Component, inject} from '@angular/core'; import {CarService} from './car.service'; @Component({ selector: 'app-root', template: ` <p>Car Listing: {{ display }}</p> `, standalone: true, }) export class AppComponent { display = ''; carService = inject(CarService); constructor() { this.display = this.carService.getCars().join(' โญ๏ธ '); } }
{ "end_byte": 376, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/answer/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/src/app/car.service.ts_0_277
import {Injectable} from '@angular/core'; @Injectable({ providedIn: 'root', }) export class CarService { cars = ['Sunflower GT', 'Flexus Sport', 'Sprout Mach One']; getCars(): string[] { return this.cars; } getCar(id: number) { return this.cars[id]; } }
{ "end_byte": 277, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/src/app/car.service.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/src/app/app.component.ts_0_234
import {Component, inject} from '@angular/core'; import {CarService} from './car.service'; @Component({ selector: 'app-root', template: ``, standalone: true, }) export class AppComponent { display = ''; constructor() {} }
{ "end_byte": 234, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/20-inject-based-di/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/README.md_0_4078
# Optimizing images Images are a big part of many applications, and can be a major contributor to application performance problems, including low [Core Web Vitals](https://web.dev/explore/learn-core-web-vitals) scores. Image optimization can be a complex topic, but Angular handles most of it for you, with the `NgOptimizedImage` directive. In this activity, you'll learn how to use `NgOptimizedImage` to ensure your images are loaded efficiently. <hr> <docs-workflow> <docs-step title="Import the NgOptimizedImage directive"> In order to leverage the `NgOptimizedImage` directive, first import it from the `@angular/common` library and add it to the component `imports` array. ```ts import { NgOptimizedImage } from '@angular/common'; @Component({ standalone: true, imports: [NgOptimizedImage], ... }) ``` </docs-step> <docs-step title="Update the src attribute to be ngSrc"> To enable the `NgOptimizedImage` directive, swap out the `src` attribute for `ngSrc`. This applies for both static image sources (i.e., `src`) and dynamic image sources (i.e., `[src]`). <docs-code language="angular-ts" highlight="[[9], [13]]"> import { NgOptimizedImage } from '@angular/common'; @Component({ standalone: true, template: ` ... <li> Static Image: <img ngSrc="/assets/logo.svg" alt="Angular logo" width="32" height="32" /> </li> <li> Dynamic Image: <img [ngSrc]="logoUrl" [alt]="logoAlt" width="32" height="32" /> </li> ... `, imports: [NgOptimizedImage], }) </docs-code> </docs-step> <docs-step title="Add width and height attributes"> Note that in the above code example, each image has both `width` and `height` attributes. In order to prevent [layout shift](https://web.dev/articles/cls), the `NgOptimizedImage` directive requires both size attributes on each image. In situations where you can't or don't want to specify a static `height` and `width` for images, you can use [the `fill` attribute](https://web.dev/articles/cls) to tell the image to act like a "background image", filling its containing element: ```angular-html <div class="image-container"> //Container div has 'position: "relative"' <img ngSrc="www.example.com/image.png" fill /> </div> ``` Note: For the `fill` image to render properly, its parent element must be styled with `position: "relative"`, `position: "fixed"`, or `position: "absolute"`. </docs-step> <docs-step title="Prioritize important images"> One of the most important optimizations for loading performance is to prioritize any image which might be the ["LCP element"](https://web.dev/articles/optimize-lcp), which is the largest on-screen graphical element when the page loads. To optimize your loading times, make sure to add the `priority` attribute to your "hero image" or any other images that you think could be an LCP element. ```ts <img ngSrc="www.example.com/image.png" height="600" width="800" priority /> ``` </docs-step> <docs-step title="Optional: Use an image loader"> `NgOptimizedImage` allows you to specify an [image loader](guide/image-optimization#configuring-an-image-loader-for-ngoptimizedimage), which tells the directive how to format URLs for your images. Using a loader allows you to define your images with short, relative URLs: ```ts providers: [ provideImgixLoader('https://my.base.url/'), ] ``` Final URL will be 'https://my.base.url/image.png' ```angular-html <img ngSrc="image.png" height="600" width="800" /> ``` Image loaders are for more than just convenience--they allow you to use the full capabilities of `NgOptimizedImage`. Learn more about these optimizations and the built-in loaders for popular CDNs [here](guide/image-optimization#configuring-an-image-loader-for-ngoptimizedimage). </docs-step> </docs-workflow> By adding this directive to your workflow, your images are now loading using best practices with the help of Angular ๐ŸŽ‰ If you would like to learn more, check out the [documentation for `NgOptimizedImage`](guide/image-optimization). Keep up the great work and let's learn about routing next.
{ "end_byte": 4078, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/answer/src/app/app.component.ts_0_243
import {Component} from '@angular/core'; import {UserComponent} from './user.component'; @Component({ selector: 'app-root', template: ` <app-user /> `, standalone: true, imports: [UserComponent], }) export class AppComponent {}
{ "end_byte": 243, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/answer/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/answer/src/app/user.component.ts_0_653
import {Component} from '@angular/core'; import {NgOptimizedImage} from '@angular/common'; @Component({ standalone: true, selector: 'app-user', template: ` <p>Username: {{ username }}</p> <p>Preferred Framework:</p> <ul> <li> Static Image: <img ngSrc="/assets/logo.svg" alt="Angular logo" width="32" height="32" /> </li> <li> Dynamic Image: <img [ngSrc]="logoUrl" [alt]="logoAlt" width="32" height="32" /> </li> </ul> `, imports: [NgOptimizedImage], }) export class UserComponent { logoUrl = '/assets/logo.svg'; logoAlt = 'Angular logo'; username = 'youngTech'; }
{ "end_byte": 653, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/answer/src/app/user.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/answer/src/public/assets/logo.svg_0_2675
<svg xmlns="http://www.w3.org/2000/svg" _ngcontent-ng-c3472466588="" width="32" height="32" viewBox="0 0 32 32" fill="none" class="adev-logo-symbol"><path _ngcontent-ng-c3472466588="" d="M22.0302 23.6181H9.54592L7.94976 27.494L15.7975 32L23.6453 27.494L22.0302 23.6181Z" fill="url(#paint0_linear_1602_15740)"/><path _ngcontent-ng-c3472466588="" d="M19.902 18.5776L15.7975 8.53461L11.6741 18.5776H19.902Z" fill="url(#paint1_linear_1602_15740)"/><path _ngcontent-ng-c3472466588="" d="M29.7449 22.4726L30.828 5.32697L19.3509 0L29.7449 22.4726Z" fill="url(#paint2_linear_1602_15740)"/><path _ngcontent-ng-c3472466588="" d="M12.2252 0L0.748047 5.32697L1.83115 22.4726L12.2252 0Z" fill="url(#paint3_linear_1602_15740)"/><defs _ngcontent-ng-c3472466588=""><linearGradient _ngcontent-ng-c3472466588="" id="paint0_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient><linearGradient _ngcontent-ng-c3472466588="" id="paint1_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient><linearGradient _ngcontent-ng-c3472466588="" id="paint2_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient><linearGradient _ngcontent-ng-c3472466588="" id="paint3_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient></defs></svg>
{ "end_byte": 2675, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/answer/src/public/assets/logo.svg" }
angular/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/src/app/app.component.ts_0_243
import {Component} from '@angular/core'; import {UserComponent} from './user.component'; @Component({ selector: 'app-root', template: ` <app-user /> `, standalone: true, imports: [UserComponent], }) export class AppComponent {}
{ "end_byte": 243, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/src/app/app.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/src/app/user.component.ts_0_537
import {Component} from '@angular/core'; @Component({ standalone: true, selector: 'app-user', template: ` <p>Username: {{ username }}</p> <p>Preferred Framework:</p> <ul> <li> Static Image: <img src="/assets/logo.svg" alt="Angular logo" /> </li> <li> Dynamic Image: <img [src]="logoUrl" [alt]="logoAlt" /> </li> </ul> `, imports: [], }) export class UserComponent { logoUrl = '/assets/logo.svg'; logoAlt = 'Angular logo'; username = 'youngTech'; }
{ "end_byte": 537, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/src/app/user.component.ts" }
angular/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/src/public/assets/logo.svg_0_2675
<svg xmlns="http://www.w3.org/2000/svg" _ngcontent-ng-c3472466588="" width="32" height="32" viewBox="0 0 32 32" fill="none" class="adev-logo-symbol"><path _ngcontent-ng-c3472466588="" d="M22.0302 23.6181H9.54592L7.94976 27.494L15.7975 32L23.6453 27.494L22.0302 23.6181Z" fill="url(#paint0_linear_1602_15740)"/><path _ngcontent-ng-c3472466588="" d="M19.902 18.5776L15.7975 8.53461L11.6741 18.5776H19.902Z" fill="url(#paint1_linear_1602_15740)"/><path _ngcontent-ng-c3472466588="" d="M29.7449 22.4726L30.828 5.32697L19.3509 0L29.7449 22.4726Z" fill="url(#paint2_linear_1602_15740)"/><path _ngcontent-ng-c3472466588="" d="M12.2252 0L0.748047 5.32697L1.83115 22.4726L12.2252 0Z" fill="url(#paint3_linear_1602_15740)"/><defs _ngcontent-ng-c3472466588=""><linearGradient _ngcontent-ng-c3472466588="" id="paint0_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient><linearGradient _ngcontent-ng-c3472466588="" id="paint1_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient><linearGradient _ngcontent-ng-c3472466588="" id="paint2_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient><linearGradient _ngcontent-ng-c3472466588="" id="paint3_linear_1602_15740" x1="-4.67856" y1="0.107889" x2="30.5691" y2="-0.175777" gradientUnits="userSpaceOnUse"><stop _ngcontent-ng-c3472466588="" offset="0.11416" stop-color="#FA2C04"/><stop _ngcontent-ng-c3472466588="" offset="0.348335" stop-color="#F11653"/><stop _ngcontent-ng-c3472466588="" offset="0.606888" stop-color="#F637E3"/><stop _ngcontent-ng-c3472466588="" offset="0.897436" stop-color="#8514F5"/></linearGradient></defs></svg>
{ "end_byte": 2675, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/11-optimizing-images/src/public/assets/logo.svg" }
angular/adev/src/content/tutorials/learn-angular/steps/7-event-handling/README.md_0_1481
# Event handling Event handling enables interactive features on web apps. It gives you the ability as a developer to respond to user actions like button presses, form submissions and more. In this activity, you'll learn how to add an event handler. <hr /> In Angular you bind to events with the parentheses syntax `()`. On a given element, wrap the event you want to bind to with parentheses and set an event handler. Consider this `button` example: ```angular-ts @Component({ ... template: `<button (click)="greet()">` }) class AppComponent { greet() { console.log('Hello, there ๐Ÿ‘‹'); } } ``` In this example, the `greet()` function will run every time the button is clicked. Take note that the `greet()` syntax includes the trailing parenthesis. Alright, your turn to give this a try: <docs-workflow> <docs-step title="Add an event handler"> Add the `onMouseOver` event handler function in the `AppComponent` class. Use the following code as the implementation: ```ts onMouseOver() { this.message = 'Way to go ๐Ÿš€'; } ``` </docs-step> <docs-step title="Bind to the template event"> Update the template code in `app.component.ts` to bind to the `mouseover` event of the `section` element. ```angular-html <section (mouseover)="onMouseOver()"> ``` </docs-step> </docs-workflow> And with a few steps in the code you've created your first event handler in Angular. Seems like you are getting pretty good at this, keep up the good work.
{ "end_byte": 1481, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/7-event-handling/README.md" }
angular/adev/src/content/tutorials/learn-angular/steps/7-event-handling/answer/src/app/app.component.ts_0_361
import {Component} from '@angular/core'; @Component({ selector: 'app-root', template: ` <section (mouseover)="onMouseOver()"> There's a secret message for you, hover to reveal: {{ message }} </section> `, standalone: true, }) export class AppComponent { message = ''; onMouseOver() { this.message = 'Way to go ๐Ÿš€'; } }
{ "end_byte": 361, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/learn-angular/steps/7-event-handling/answer/src/app/app.component.ts" }