_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
angular/adev/src/content/examples/router/src/app/page-not-found/page-not-found.component.ts_0_250
import {Component} from '@angular/core'; @Component({ selector: 'app-page-not-found', templateUrl: './page-not-found.component.html', styleUrls: ['./page-not-found.component.css'], standalone: false, }) export class PageNotFoundComponent {}
{ "end_byte": 250, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/page-not-found/page-not-found.component.ts" }
angular/adev/src/content/examples/router/src/app/page-not-found/page-not-found.component.html_0_23
<h2>Page not found</h2>
{ "end_byte": 23, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/page-not-found/page-not-found.component.html" }
angular/adev/src/content/examples/router/src/app/auth/auth.guard.4.ts_0_718
// #docplaster // #docregion import {inject} from '@angular/core'; import {Router, NavigationExtras} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const authService = inject(AuthService); const router = inject(Router); if (authService.isLoggedIn) { return true; } // Create a dummy session id const sessionId = 123456789; // Set our navigation extras object // that contains our global query params and fragment const navigationExtras: NavigationExtras = { queryParams: {session_id: sessionId}, fragment: 'anchor', }; // Redirect to the login page with extras return router.createUrlTree(['/login'], navigationExtras); };
{ "end_byte": 718, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth.guard.4.ts" }
angular/adev/src/content/examples/router/src/app/auth/auth.service.ts_0_507
// #docregion import {Injectable} from '@angular/core'; import {Observable, of} from 'rxjs'; import {tap, delay} from 'rxjs/operators'; @Injectable({ providedIn: 'root', }) export class AuthService { isLoggedIn = false; // store the URL so we can redirect after logging in redirectUrl: string | null = null; login(): Observable<boolean> { return of(true).pipe( delay(1000), tap(() => (this.isLoggedIn = true)), ); } logout(): void { this.isLoggedIn = false; } }
{ "end_byte": 507, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth.service.ts" }
angular/adev/src/content/examples/router/src/app/auth/auth.guard.1.ts_0_130
// #docregion export const authGuard = () => { console.log('authGuard#canActivate called'); return true; }; // #enddocregion
{ "end_byte": 130, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth.guard.1.ts" }
angular/adev/src/content/examples/router/src/app/auth/auth.guard.ts_0_704
// #docplaster import {inject} from '@angular/core'; import {Router, NavigationExtras} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const router = inject(Router); const authService = inject(AuthService); if (authService.isLoggedIn) { return true; } // Create a dummy session id const sessionId = 123456789; // Set our navigation extras object // that contains our global query params and fragment const navigationExtras: NavigationExtras = { queryParams: {session_id: sessionId}, fragment: 'anchor', }; // Navigate to the login page with extras return router.createUrlTree(['/login'], navigationExtras); };
{ "end_byte": 704, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth.guard.ts" }
angular/adev/src/content/examples/router/src/app/auth/auth-routing.module.ts_0_447
// #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {authGuard} from './auth.guard'; import {AuthService} from './auth.service'; import {LoginComponent} from './login/login.component'; const authRoutes: Routes = [{path: 'login', component: LoginComponent}]; @NgModule({ imports: [RouterModule.forChild(authRoutes)], exports: [RouterModule], }) export class AuthRoutingModule {}
{ "end_byte": 447, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth-routing.module.ts" }
angular/adev/src/content/examples/router/src/app/auth/auth.module.ts_0_380
import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {FormsModule} from '@angular/forms'; import {LoginComponent} from './login/login.component'; import {AuthRoutingModule} from './auth-routing.module'; @NgModule({ imports: [CommonModule, FormsModule, AuthRoutingModule], declarations: [LoginComponent], }) export class AuthModule {}
{ "end_byte": 380, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth.module.ts" }
angular/adev/src/content/examples/router/src/app/auth/auth.guard.2.ts_0_391
// #docregion import {inject} from '@angular/core'; import {Router} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const authService = inject(AuthService); const router = inject(Router); if (authService.isLoggedIn) { return true; } // Redirect to the login page return router.parseUrl('/login'); }; // #enddocregion
{ "end_byte": 391, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth.guard.2.ts" }
angular/adev/src/content/examples/router/src/app/auth/auth.guard.3.ts_0_358
import {inject} from '@angular/core'; import {Router} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const authService = inject(AuthService); const router = inject(Router); if (authService.isLoggedIn) { return true; } // Redirect to the login page return router.parseUrl('/login'); };
{ "end_byte": 358, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/auth.guard.3.ts" }
angular/adev/src/content/examples/router/src/app/auth/login/login.component.ts_0_1466
// #docregion import {Component} from '@angular/core'; import {NavigationExtras, Router} from '@angular/router'; import {AuthService} from '../auth.service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'], standalone: false, }) export class LoginComponent { message: string; constructor( public authService: AuthService, public router: Router, ) { this.message = this.getMessage(); } getMessage() { return 'Logged ' + (this.authService.isLoggedIn ? 'in' : 'out'); } login() { this.message = 'Trying to log in ...'; this.authService.login().subscribe(() => { this.message = this.getMessage(); if (this.authService.isLoggedIn) { // Usually you would use the redirect URL from the auth service. // However to keep the example simple, we will always redirect to `/admin`. const redirectUrl = '/admin'; // #docregion preserve // Set our navigation extras object // that passes on our global query params and fragment const navigationExtras: NavigationExtras = { queryParamsHandling: 'preserve', preserveFragment: true, }; // Redirect the user this.router.navigate([redirectUrl], navigationExtras); // #enddocregion preserve } }); } logout() { this.authService.logout(); this.message = this.getMessage(); } }
{ "end_byte": 1466, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/login/login.component.ts" }
angular/adev/src/content/examples/router/src/app/auth/login/login.component.1.ts_0_1116
// #docregion import {Component} from '@angular/core'; import {Router} from '@angular/router'; import {AuthService} from '../auth.service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'], standalone: false, }) export class LoginComponent { message: string; constructor( public authService: AuthService, public router: Router, ) { this.message = this.getMessage(); } getMessage() { return 'Logged ' + (this.authService.isLoggedIn ? 'in' : 'out'); } login() { this.message = 'Trying to log in ...'; this.authService.login().subscribe(() => { this.message = this.getMessage(); if (this.authService.isLoggedIn) { // Usually you would use the redirect URL from the auth service. // However to keep the example simple, we will always redirect to `/admin`. const redirectUrl = '/admin'; // Redirect the user this.router.navigate([redirectUrl]); } }); } logout() { this.authService.logout(); this.message = this.getMessage(); } }
{ "end_byte": 1116, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/login/login.component.1.ts" }
angular/adev/src/content/examples/router/src/app/auth/login/login.component.html_0_225
<h2>Login</h2> <p>{{ message }}</p> <p> <button type="button" (click)="login()" *ngIf="!authService.isLoggedIn">Login</button> <button type="button" (click)="logout()" *ngIf="authService.isLoggedIn">Logout</button> </p>
{ "end_byte": 225, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/auth/login/login.component.html" }
angular/adev/src/content/examples/router/src/app/heroes/heroes.module.ts_0_497
import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {FormsModule} from '@angular/forms'; import {HeroListComponent} from './hero-list/hero-list.component'; import {HeroDetailComponent} from './hero-detail/hero-detail.component'; import {HeroesRoutingModule} from './heroes-routing.module'; @NgModule({ imports: [CommonModule, FormsModule, HeroesRoutingModule], declarations: [HeroListComponent, HeroDetailComponent], }) export class HeroesModule {}
{ "end_byte": 497, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/heroes.module.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero.ts_0_56
export interface Hero { id: number; name: string; }
{ "end_byte": 56, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero.ts" }
angular/adev/src/content/examples/router/src/app/heroes/heroes-routing.module.ts_0_700
// #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {HeroListComponent} from './hero-list/hero-list.component'; import {HeroDetailComponent} from './hero-detail/hero-detail.component'; const heroesRoutes: Routes = [ {path: 'heroes', redirectTo: '/superheroes'}, {path: 'hero/:id', redirectTo: '/superhero/:id'}, {path: 'superheroes', component: HeroListComponent, data: {animation: 'heroes'}}, {path: 'superhero/:id', component: HeroDetailComponent, data: {animation: 'hero'}}, ]; @NgModule({ imports: [RouterModule.forChild(heroesRoutes)], exports: [RouterModule], }) export class HeroesRoutingModule {} // #enddocregion
{ "end_byte": 700, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/heroes-routing.module.ts" }
angular/adev/src/content/examples/router/src/app/heroes/mock-heroes.ts_0_328
import {Hero} from './hero'; export const HEROES: Hero[] = [ {id: 12, name: 'Dr. Nice'}, {id: 13, name: 'Bombasto'}, {id: 14, name: 'Celeritas'}, {id: 15, name: 'Magneta'}, {id: 16, name: 'RubberMan'}, {id: 17, name: 'Dynama'}, {id: 18, name: 'Dr. IQ'}, {id: 19, name: 'Magma'}, {id: 20, name: 'Tornado'}, ];
{ "end_byte": 328, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/mock-heroes.ts" }
angular/adev/src/content/examples/router/src/app/heroes/heroes-routing.module.2.ts_0_590
// #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {HeroListComponent} from './hero-list/hero-list.component'; import {HeroDetailComponent} from './hero-detail/hero-detail.component'; const heroesRoutes: Routes = [ {path: 'heroes', component: HeroListComponent, data: {animation: 'heroes'}}, {path: 'hero/:id', component: HeroDetailComponent, data: {animation: 'hero'}}, ]; @NgModule({ imports: [RouterModule.forChild(heroesRoutes)], exports: [RouterModule], }) export class HeroesRoutingModule {} // #enddocregion
{ "end_byte": 590, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/heroes-routing.module.2.ts" }
angular/adev/src/content/examples/router/src/app/heroes/heroes-routing.module.1.ts_0_605
// #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {HeroListComponent} from './hero-list/hero-list.component'; import {HeroDetailComponent} from './hero-detail/hero-detail.component'; const heroesRoutes: Routes = [ {path: 'heroes', component: HeroListComponent}, // #docregion hero-detail-route {path: 'hero/:id', component: HeroDetailComponent}, // #enddocregion hero-detail-route ]; @NgModule({ imports: [RouterModule.forChild(heroesRoutes)], exports: [RouterModule], }) export class HeroesRoutingModule {} // #enddocregion
{ "end_byte": 605, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/heroes-routing.module.1.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero.service.ts_0_764
// #docregion import {Injectable} from '@angular/core'; import {Observable, of} from 'rxjs'; import {map} from 'rxjs/operators'; import {Hero} from './hero'; import {HEROES} from './mock-heroes'; import {MessageService} from '../message.service'; @Injectable({ providedIn: 'root', }) export class HeroService { constructor(private messageService: MessageService) {} getHeroes(): Observable<Hero[]> { // TODO: send the message _after_ fetching the heroes this.messageService.add('HeroService: fetched heroes'); return of(HEROES); } getHero(id: number | string) { return this.getHeroes().pipe( // (+) before `id` turns the string into a number map((heroes: Hero[]) => heroes.find((hero) => hero.id === +id)!), ); } }
{ "end_byte": 764, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero.service.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.3.ts_0_1326
// #docplaster // #docregion // #docregion rxjs-operator-import import {switchMap} from 'rxjs/operators'; // #enddocregion rxjs-operator-import import {Component, OnInit} from '@angular/core'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Observable} from 'rxjs'; import {HeroService} from '../hero.service'; import {Hero} from '../hero'; @Component({ selector: 'app-hero-detail', templateUrl: './hero-detail.component.html', styleUrls: ['./hero-detail.component.css'], standalone: false, }) export class HeroDetailComponent implements OnInit { hero$!: Observable<Hero>; // #docregion ctor constructor( private route: ActivatedRoute, private router: Router, private service: HeroService, ) {} // #enddocregion ctor // #docregion ngOnInit ngOnInit() { this.hero$ = this.route.paramMap.pipe( switchMap((params: ParamMap) => this.service.getHero(params.get('id')!)), ); } // #enddocregion ngOnInit // #docregion gotoHeroes gotoHeroes(hero: Hero) { const heroId = hero ? hero.id : null; // Pass along the hero id if available // so that the HeroList component can select that hero. // Include a junk 'foo' property for fun. this.router.navigate(['/heroes', {id: heroId, foo: 'foo'}]); } // #enddocregion gotoHeroes }
{ "end_byte": 1326, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.3.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.2.ts_0_847
// Snapshot version // #docregion import {Component, OnInit} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Observable} from 'rxjs'; import {HeroService} from '../hero.service'; import {Hero} from '../hero'; @Component({ selector: 'app-hero-detail', templateUrl: './hero-detail.component.html', styleUrls: ['./hero-detail.component.css'], standalone: false, }) export class HeroDetailComponent implements OnInit { hero$!: Observable<Hero>; constructor( private route: ActivatedRoute, private router: Router, private service: HeroService, ) {} // #docregion snapshot ngOnInit() { const id = this.route.snapshot.paramMap.get('id')!; this.hero$ = this.service.getHero(id); } // #enddocregion snapshot gotoHeroes() { this.router.navigate(['/heroes']); } }
{ "end_byte": 847, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.2.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.ts_0_1156
// #docplaster // #docregion import {Component, OnInit} from '@angular/core'; import {ActivatedRoute, ParamMap, Router} from '@angular/router'; import {Observable} from 'rxjs'; import {switchMap} from 'rxjs/operators'; import {Hero} from '../hero'; import {HeroService} from '../hero.service'; @Component({ selector: 'app-hero-detail', templateUrl: './hero-detail.component.html', styleUrls: ['./hero-detail.component.css'], standalone: false, }) export class HeroDetailComponent implements OnInit { hero$!: Observable<Hero>; constructor( private route: ActivatedRoute, private router: Router, private service: HeroService, ) {} ngOnInit() { this.hero$ = this.route.paramMap.pipe( switchMap((params: ParamMap) => this.service.getHero(params.get('id')!)), ); } // #docregion redirect gotoHeroes(hero: Hero) { const heroId = hero ? hero.id : null; // Pass along the hero id if available // so that the HeroList component can select that hero. // Include a junk 'foo' property for fun. this.router.navigate(['/superheroes', {id: heroId, foo: 'foo'}]); } // #enddocregion redirect }
{ "end_byte": 1156, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.css_0_84
button { margin-top: 1rem; } label { display: block; margin-bottom: .5rem; }
{ "end_byte": 84, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.css" }
angular/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.1.ts_0_975
// #docplaster // #docregion import {switchMap} from 'rxjs/operators'; import {Component, OnInit} from '@angular/core'; import {Observable} from 'rxjs'; // #docregion imports import {Router, ActivatedRoute, ParamMap} from '@angular/router'; // #enddocregion imports import {HeroService} from '../hero.service'; import {Hero} from '../hero'; @Component({ selector: 'app-hero-detail', templateUrl: './hero-detail.component.html', styleUrls: ['./hero-detail.component.css'], standalone: false, }) export class HeroDetailComponent implements OnInit { hero$!: Observable<Hero>; constructor( private route: ActivatedRoute, private router: Router, private service: HeroService, ) {} ngOnInit() { this.hero$ = this.route.paramMap.pipe( switchMap((params: ParamMap) => this.service.getHero(params.get('id')!)), ); } // #docregion gotoHeroes gotoHeroes() { this.router.navigate(['/heroes']); } // #enddocregion gotoHeroes }
{ "end_byte": 975, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.1.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.html_0_304
<h2>Heroes</h2> <div *ngIf="hero$ | async as hero"> <h3>{{ hero.name }}</h3> <p>Id: {{ hero.id }}</p> <label for="hero-name">Hero name: </label> <input type="text" id="hero-name" [(ngModel)]="hero.name" placeholder="name"/> <button type="button" (click)="gotoHeroes(hero)">Back</button> </div>
{ "end_byte": 304, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.html" }
angular/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.4.ts_0_982
// #docplaster // #docregion import {Component, Input, OnInit} from '@angular/core'; import {Router} from '@angular/router'; import {Observable} from 'rxjs'; import {Hero} from '../hero'; import {HeroService} from '../hero.service'; @Component({ selector: 'app-hero-detail', templateUrl: './hero-detail.component.html', styleUrls: ['./hero-detail.component.css'], standalone: false, }) export class HeroDetailComponent { hero$!: Observable<Hero>; constructor( private router: Router, private service: HeroService, ) {} // #docregion id-input @Input() set id(heroId: string) { this.hero$ = this.service.getHero(heroId); } // #enddocregion id-input gotoHeroes(hero: Hero) { const heroId = hero ? hero.id : null; // Pass along the hero id if available // so that the HeroList component can select that hero. // Include a junk 'foo' property for fun. this.router.navigate(['/superheroes', {id: heroId, foo: 'foo'}]); } }
{ "end_byte": 982, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-detail/hero-detail.component.4.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.css_0_882
/* HeroListComponent's private CSS styles */ .heroes { margin: 0 0 2em 0; list-style-type: none; padding: 0; width: 100%; } .heroes li { position: relative; cursor: pointer; } .heroes li:hover { left: .1em; } .heroes a { color: black; text-decoration: none; display: block; font-size: 1.2rem; background-color: #eee; margin: .5rem .5rem .5rem 0; padding: .5rem 0; border-radius: 4px; } .heroes a:hover { color: #2c3a41; background-color: #e6e6e6; } .heroes a:active { background-color: #525252; color: #fafafa; } /* #docregion selected */ .heroes .selected a { background-color: #d6e6f7; } .heroes .selected a:hover { background-color: #bdd7f5; } /* #enddocregion selected */ .heroes .badge { padding: .5em .6em; color: white; background-color: #435b60; min-width: 16px; margin-right: .8em; border-radius: 4px 0 0 4px; }
{ "end_byte": 882, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.css" }
angular/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.1.html_0_452
<h2>Heroes</h2> <ul class="items"> <li *ngFor="let hero of heroes$ | async"> <!-- #docregion nav-to-detail --> <!-- #docregion link-parameters-array --> <a [routerLink]="['/hero', hero.id]"> <!-- #enddocregion link-parameters-array --> <span class="badge">{{ hero.id }}</span>{{ hero.name }} </a> <!-- #enddocregion nav-to-detail --> </li> </ul> <button type="button" routerLink="/sidekicks">Go to sidekicks</button>
{ "end_byte": 452, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.1.html" }
angular/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.1.ts_0_561
// TODO: Feature Componentized like HeroCenter import {Component, OnInit} from '@angular/core'; import {Observable} from 'rxjs'; import {HeroService} from '../hero.service'; import {Hero} from '../hero'; @Component({ selector: 'app-hero-list', templateUrl: './hero-list.component.1.html', styleUrls: ['./hero-list.component.css'], standalone: false, }) export class HeroListComponent implements OnInit { heroes$!: Observable<Hero[]>; constructor(private service: HeroService) {} ngOnInit() { this.heroes$ = this.service.getHeroes(); } }
{ "end_byte": 561, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.1.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.ts_0_1086
// #docplaster // #docregion // TODO: Feature Componentized like CrisisCenter // #docregion rxjs-imports import {Observable} from 'rxjs'; import {switchMap} from 'rxjs/operators'; // #enddocregion rxjs-imports import {Component, OnInit} from '@angular/core'; // #docregion import-router import {ActivatedRoute} from '@angular/router'; // #enddocregion import-router import {HeroService} from '../hero.service'; import {Hero} from '../hero'; @Component({ selector: 'app-hero-list', templateUrl: './hero-list.component.html', styleUrls: ['./hero-list.component.css'], standalone: false, }) // #docregion ctor export class HeroListComponent implements OnInit { heroes$!: Observable<Hero[]>; selectedId = 0; constructor( private service: HeroService, private route: ActivatedRoute, ) {} ngOnInit() { this.heroes$ = this.route.paramMap.pipe( switchMap((params) => { this.selectedId = parseInt(params.get('id')!, 10); return this.service.getHeroes(); }), ); } // #enddocregion ctor // #docregion ctor } // #enddocregion
{ "end_byte": 1086, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.ts" }
angular/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.html_0_321
<h2>Heroes</h2> <ul class="heroes"> <li *ngFor="let hero of heroes$ | async" [class.selected]="hero.id === selectedId"> <a [routerLink]="['/hero', hero.id]"> <span class="badge">{{ hero.id }}</span>{{ hero.name }} </a> </li> </ul> <button type="button" routerLink="/sidekicks">Go to sidekicks</button>
{ "end_byte": 321, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/heroes/hero-list/hero-list.component.html" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.3.ts_0_1107
import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {CrisisCenterHomeComponent} from './crisis-center-home/crisis-center-home.component'; import {CrisisListComponent} from './crisis-list/crisis-list.component'; import {CrisisCenterComponent} from './crisis-center/crisis-center.component'; import {CrisisDetailComponent} from './crisis-detail/crisis-detail.component'; import {canDeactivateGuard} from '../can-deactivate.guard'; const crisisCenterRoutes: Routes = [ { path: 'crisis-center', component: CrisisCenterComponent, children: [ { path: '', component: CrisisListComponent, children: [ { path: ':id', component: CrisisDetailComponent, canDeactivate: [canDeactivateGuard], }, { path: '', component: CrisisCenterHomeComponent, }, ], }, ], }, ]; @NgModule({ imports: [RouterModule.forChild(crisisCenterRoutes)], exports: [RouterModule], }) export class CrisisCenterRoutingModule {}
{ "end_byte": 1107, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.3.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-detail-resolver.1.ts_0_57
// #docregion export function crisisDetailResolver() {}
{ "end_byte": 57, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-detail-resolver.1.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis.service.ts_0_931
// #docplaster // #docregion import {BehaviorSubject} from 'rxjs'; import {map} from 'rxjs/operators'; import {Injectable} from '@angular/core'; import {MessageService} from '../message.service'; import {Crisis} from './crisis'; import {CRISES} from './mock-crises'; @Injectable({ providedIn: 'root', }) export class CrisisService { static nextCrisisId = 100; private crises$: BehaviorSubject<Crisis[]> = new BehaviorSubject<Crisis[]>(CRISES); constructor(private messageService: MessageService) {} getCrises() { return this.crises$; } getCrisis(id: number | string) { return this.getCrises().pipe(map((crises) => crises.find((crisis) => crisis.id === +id)!)); } // #enddocregion addCrisis(name: string) { name = name.trim(); if (name) { const crisis = {id: CrisisService.nextCrisisId++, name}; CRISES.push(crisis); this.crises$.next(CRISES); } } // #docregion }
{ "end_byte": 931, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis.service.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center.module.ts_0_795
// #docregion import {NgModule} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {CommonModule} from '@angular/common'; import {CrisisCenterHomeComponent} from './crisis-center-home/crisis-center-home.component'; import {CrisisListComponent} from './crisis-list/crisis-list.component'; import {CrisisCenterComponent} from './crisis-center/crisis-center.component'; import {CrisisDetailComponent} from './crisis-detail/crisis-detail.component'; import {CrisisCenterRoutingModule} from './crisis-center-routing.module'; @NgModule({ imports: [CommonModule, FormsModule, CrisisCenterRoutingModule], declarations: [ CrisisCenterComponent, CrisisListComponent, CrisisCenterHomeComponent, CrisisDetailComponent, ], }) export class CrisisCenterModule {}
{ "end_byte": 795, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center.module.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.2.ts_0_1252
import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {CrisisCenterHomeComponent} from './crisis-center-home/crisis-center-home.component'; import {CrisisListComponent} from './crisis-list/crisis-list.component'; import {CrisisCenterComponent} from './crisis-center/crisis-center.component'; import {CrisisDetailComponent} from './crisis-detail/crisis-detail.component'; import {canDeactivateGuard} from '../can-deactivate.guard'; import {crisisDetailResolver} from './crisis-detail-resolver'; const crisisCenterRoutes: Routes = [ { path: 'crisis-center', component: CrisisCenterComponent, children: [ { path: '', component: CrisisListComponent, children: [ { path: ':id', component: CrisisDetailComponent, canDeactivate: [canDeactivateGuard], resolve: { crisis: crisisDetailResolver, }, }, { path: '', component: CrisisCenterHomeComponent, }, ], }, ], }, ]; @NgModule({ imports: [RouterModule.forChild(crisisCenterRoutes)], exports: [RouterModule], }) export class CrisisCenterRoutingModule {}
{ "end_byte": 1252, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.2.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.ts_0_1285
// #docplaster // #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {CrisisCenterHomeComponent} from './crisis-center-home/crisis-center-home.component'; import {CrisisListComponent} from './crisis-list/crisis-list.component'; import {CrisisCenterComponent} from './crisis-center/crisis-center.component'; import {CrisisDetailComponent} from './crisis-detail/crisis-detail.component'; import {canDeactivateGuard} from '../can-deactivate.guard'; import {crisisDetailResolver} from './crisis-detail-resolver'; const crisisCenterRoutes: Routes = [ { path: '', component: CrisisCenterComponent, children: [ { path: '', component: CrisisListComponent, children: [ { path: ':id', component: CrisisDetailComponent, canDeactivate: [canDeactivateGuard], resolve: { crisis: crisisDetailResolver, }, }, { path: '', component: CrisisCenterHomeComponent, }, ], }, ], }, ]; @NgModule({ imports: [RouterModule.forChild(crisisCenterRoutes)], exports: [RouterModule], }) export class CrisisCenterRoutingModule {} // #enddocregion
{ "end_byte": 1285, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/mock-crises.ts_0_287
// #docregion import {Crisis} from './crisis'; export const CRISES: Crisis[] = [ {id: 1, name: 'Dragon Burning Cities'}, {id: 2, name: 'Sky Rains Great White Sharks'}, {id: 3, name: 'Giant Asteroid Heading For Earth'}, {id: 4, name: 'Procrastinators Meeting Delayed Again'}, ];
{ "end_byte": 287, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/mock-crises.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-detail-resolver.ts_0_721
// #docregion import {inject} from '@angular/core'; import {ActivatedRouteSnapshot, ResolveFn, Router} from '@angular/router'; import {EMPTY, of} from 'rxjs'; import {mergeMap} from 'rxjs/operators'; import {Crisis} from './crisis'; import {CrisisService} from './crisis.service'; export const crisisDetailResolver: ResolveFn<Crisis> = (route: ActivatedRouteSnapshot) => { const router = inject(Router); const cs = inject(CrisisService); const id = route.paramMap.get('id')!; return cs.getCrisis(id).pipe( mergeMap((crisis) => { if (crisis) { return of(crisis); } else { // id not found router.navigate(['/crisis-center']); return EMPTY; } }), ); };
{ "end_byte": 721, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-detail-resolver.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.1.ts_0_1088
// #docplaster // #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {CrisisCenterHomeComponent} from './crisis-center-home/crisis-center-home.component'; import {CrisisListComponent} from './crisis-list/crisis-list.component'; import {CrisisCenterComponent} from './crisis-center/crisis-center.component'; import {CrisisDetailComponent} from './crisis-detail/crisis-detail.component'; // #docregion routes const crisisCenterRoutes: Routes = [ { path: 'crisis-center', component: CrisisCenterComponent, children: [ { path: '', component: CrisisListComponent, children: [ { path: ':id', component: CrisisDetailComponent, }, { path: '', component: CrisisCenterHomeComponent, }, ], }, ], }, ]; // #enddocregion routes @NgModule({ imports: [RouterModule.forChild(crisisCenterRoutes)], exports: [RouterModule], }) export class CrisisCenterRoutingModule {} // #enddocregion
{ "end_byte": 1088, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.1.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis.ts_0_58
export interface Crisis { id: number; name: string; }
{ "end_byte": 58, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.4.ts_0_1298
// #docplaster // #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {CrisisCenterHomeComponent} from './crisis-center-home/crisis-center-home.component'; import {CrisisListComponent} from './crisis-list/crisis-list.component'; import {CrisisCenterComponent} from './crisis-center/crisis-center.component'; import {CrisisDetailComponent} from './crisis-detail/crisis-detail.component'; import {canDeactivateGuard} from '../can-deactivate.guard'; import {crisisDetailResolver} from './crisis-detail-resolver'; const crisisCenterRoutes: Routes = [ { path: 'crisis-center', component: CrisisCenterComponent, children: [ { path: '', component: CrisisListComponent, children: [ { path: ':id', component: CrisisDetailComponent, canDeactivate: [canDeactivateGuard], resolve: { crisis: crisisDetailResolver, }, }, { path: '', component: CrisisCenterHomeComponent, }, ], }, ], }, ]; @NgModule({ imports: [RouterModule.forChild(crisisCenterRoutes)], exports: [RouterModule], }) export class CrisisCenterRoutingModule {} // #enddocregion
{ "end_byte": 1298, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center-routing.module.4.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center/crisis-center.component.ts_0_261
// #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-crisis-center', templateUrl: './crisis-center.component.html', styleUrls: ['./crisis-center.component.css'], standalone: false, }) export class CrisisCenterComponent {}
{ "end_byte": 261, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center/crisis-center.component.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center/crisis-center.component.html_0_55
<h2>Crisis Center</h2> <router-outlet></router-outlet>
{ "end_byte": 55, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center/crisis-center.component.html" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center-home/crisis-center-home.component.ts_0_280
// #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-crisis-center-home', templateUrl: './crisis-center-home.component.html', styleUrls: ['./crisis-center-home.component.css'], standalone: false, }) export class CrisisCenterHomeComponent {}
{ "end_byte": 280, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center-home/crisis-center-home.component.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-center-home/crisis-center-home.component.html_0_38
<h3>Welcome to the Crisis Center</h3>
{ "end_byte": 38, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-center-home/crisis-center-home.component.html" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.css_0_78
h2 { font-size: 1.5rem; } input { font-size: 1rem; margin-top: 1rem; }
{ "end_byte": 78, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.css" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.ts_0_1999
// #docplaster // #docregion import {Component, OnInit} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Observable} from 'rxjs'; import {Crisis} from '../crisis'; import {DialogService} from '../../dialog.service'; @Component({ selector: 'app-crisis-detail', templateUrl: './crisis-detail.component.html', styleUrls: ['./crisis-detail.component.css'], standalone: false, }) export class CrisisDetailComponent implements OnInit { crisis!: Crisis; editName = ''; constructor( private route: ActivatedRoute, private router: Router, public dialogService: DialogService, ) {} // #docregion ngOnInit ngOnInit() { this.route.data.subscribe((data) => { const crisis: Crisis = data['crisis']; this.editName = crisis.name; this.crisis = crisis; }); } // #enddocregion ngOnInit // #docregion cancel-save cancel() { this.gotoCrises(); } save() { this.crisis.name = this.editName; this.gotoCrises(); } // #enddocregion cancel-save // #docregion canDeactivate canDeactivate(): Observable<boolean> | boolean { // Allow synchronous navigation (`true`) if no crisis or the crisis is unchanged if (!this.crisis || this.crisis.name === this.editName) { return true; } // Otherwise ask the user with the dialog service and return its // observable which resolves to true or false when the user decides return this.dialogService.confirm('Discard changes?'); } // #enddocregion canDeactivate gotoCrises() { const crisisId = this.crisis ? this.crisis.id : null; // Pass along the crisis id if available // so that the CrisisListComponent can select that crisis. // Add a totally useless `foo` parameter for kicks. // #docregion gotoCrises-navigate // Relative navigation back to the crises this.router.navigate(['../', {id: crisisId, foo: 'foo'}], {relativeTo: this.route}); // #enddocregion gotoCrises-navigate } }
{ "end_byte": 1999, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.html_0_349
<div *ngIf="crisis"> <h3>{{ editName }}</h3> <p>Id: {{ crisis.id }}</p> <label for="crisis-name">Crisis name: </label> <input type="text" id="crisis-name" [(ngModel)]="editName" placeholder="name"/> <div> <button type="button" (click)="save()">Save</button> <button type="button" (click)="cancel()">Cancel</button> </div> </div>
{ "end_byte": 349, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.html" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.1.ts_0_2031
import {Component, OnInit} from '@angular/core'; import {ActivatedRoute, Router, ParamMap} from '@angular/router'; import {Observable} from 'rxjs'; import {switchMap} from 'rxjs/operators'; import {CrisisService} from '../crisis.service'; import {Crisis} from '../crisis'; import {DialogService} from '../../dialog.service'; @Component({ selector: 'app-crisis-detail', templateUrl: './crisis-detail.component.html', styleUrls: ['./crisis-detail.component.css'], standalone: false, }) export class CrisisDetailComponent implements OnInit { crisis!: Crisis; editName = ''; constructor( private service: CrisisService, private router: Router, private route: ActivatedRoute, public dialogService: DialogService, ) {} ngOnInit() { this.route.paramMap .pipe(switchMap((params: ParamMap) => this.service.getCrisis(params.get('id')!))) .subscribe((crisis: Crisis) => { if (crisis) { this.editName = crisis.name; this.crisis = crisis; } else { // id not found this.gotoCrises(); } }); } cancel() { this.gotoCrises(); } save() { this.crisis.name = this.editName; this.gotoCrises(); } canDeactivate(): Observable<boolean> | boolean { // Allow synchronous navigation (`true`) if no crisis or the crisis is unchanged if (!this.crisis || this.crisis.name === this.editName) { return true; } // Otherwise ask the user with the dialog service and return its // observable which resolves to true or false when the user decides return this.dialogService.confirm('Discard changes?'); } gotoCrises() { const crisisId = this.crisis ? this.crisis.id : null; // Pass along the crisis id if available // so that the CrisisListComponent can select that crisis. // Add a totally useless `foo` parameter for kicks. // Relative navigation back to the crises this.router.navigate(['../', {id: crisisId, foo: 'foo'}], {relativeTo: this.route}); } }
{ "end_byte": 2031, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-detail/crisis-detail.component.1.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.ts_0_843
import {Component, OnInit} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {CrisisService} from '../crisis.service'; import {Crisis} from '../crisis'; import {Observable} from 'rxjs'; import {switchMap} from 'rxjs/operators'; @Component({ selector: 'app-crisis-list', templateUrl: './crisis-list.component.html', styleUrls: ['./crisis-list.component.css'], standalone: false, }) export class CrisisListComponent implements OnInit { crises$?: Observable<Crisis[]>; selectedId = 0; constructor( private service: CrisisService, private route: ActivatedRoute, ) {} ngOnInit() { this.crises$ = this.route.firstChild?.paramMap.pipe( switchMap((params) => { this.selectedId = parseInt(params.get('id')!, 10); return this.service.getCrises(); }), ); } }
{ "end_byte": 843, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.ts" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.css_0_960
/* CrisisListComponent's private CSS styles */ .crises { margin: 0 0 2em 0; list-style-type: none; padding: 0; } .crises li { position: relative; cursor: pointer; } .crises li:hover { left: 0.1em; } .crises a { color: black; text-decoration: none; display: block; background-color: #eee; margin: 0.5em 0; border-radius: 4px; line-height: 2rem; } @media (min-width: 600px) { .crises a { font-size: 1.2rem; padding: 0.5em 0; line-height: 1.4rem; } } .crises a:hover { color: #2c3a41; background-color: #e6e6e6; left: 0.1em; } .crises .selected a { background: #d6e6f7; } .crises .selected a:hover { background-color: #bdd7f5; } .heroes .selected a { background-color: #d6e6f7; } .heroes .selected a:hover { background-color: #bdd7f5; } .crises .badge { padding: 0.5em 0.6em; color: white; background-color: #435b60; min-width: 16px; margin-right: 0.8em; border-radius: 4px 0 0 4px; }
{ "end_byte": 960, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.css" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.html_0_267
<ul class="crises"> <li *ngFor="let crisis of crises$ | async" [class.selected]="crisis.id === selectedId"> <a [routerLink]="[crisis.id]"> <span class="badge">{{ crisis.id }}</span>{{ crisis.name }} </a> </li> </ul> <router-outlet></router-outlet>
{ "end_byte": 267, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.html" }
angular/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.1.ts_0_851
import {Component, OnInit} from '@angular/core'; import {ActivatedRoute, ParamMap} from '@angular/router'; import {CrisisService} from '../crisis.service'; import {Crisis} from '../crisis'; import {Observable} from 'rxjs'; import {switchMap} from 'rxjs/operators'; @Component({ selector: 'app-crisis-list', templateUrl: './crisis-list.component.html', styleUrls: ['./crisis-list.component.css'], standalone: false, }) export class CrisisListComponent implements OnInit { crises$!: Observable<Crisis[]>; selectedId = 0; constructor( private service: CrisisService, private route: ActivatedRoute, ) {} ngOnInit() { this.crises$ = this.route.paramMap.pipe( switchMap((params: ParamMap) => { this.selectedId = parseInt(params.get('id')!, 10); return this.service.getCrises(); }), ); } }
{ "end_byte": 851, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-center/crisis-list/crisis-list.component.1.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin-routing.module.1.ts_0_988
// #docplaster // #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {AdminComponent} from './admin/admin.component'; import {AdminDashboardComponent} from './admin-dashboard/admin-dashboard.component'; import {ManageCrisesComponent} from './manage-crises/manage-crises.component'; import {ManageHeroesComponent} from './manage-heroes/manage-heroes.component'; // #docregion admin-routes const adminRoutes: Routes = [ { path: 'admin', component: AdminComponent, children: [ { path: '', children: [ {path: 'crises', component: ManageCrisesComponent}, {path: 'heroes', component: ManageHeroesComponent}, {path: '', component: AdminDashboardComponent}, ], }, ], }, ]; @NgModule({ imports: [RouterModule.forChild(adminRoutes)], exports: [RouterModule], }) export class AdminRoutingModule {} // #enddocregion admin-routes // #enddocregion
{ "end_byte": 988, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-routing.module.1.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin.module.ts_0_677
// #docregion import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {AdminComponent} from './admin/admin.component'; import {AdminDashboardComponent} from './admin-dashboard/admin-dashboard.component'; import {ManageCrisesComponent} from './manage-crises/manage-crises.component'; import {ManageHeroesComponent} from './manage-heroes/manage-heroes.component'; import {AdminRoutingModule} from './admin-routing.module'; @NgModule({ imports: [CommonModule, AdminRoutingModule], declarations: [ AdminComponent, AdminDashboardComponent, ManageCrisesComponent, ManageHeroesComponent, ], }) export class AdminModule {}
{ "end_byte": 677, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin.module.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin-routing.module.ts_0_1042
// #docplaster // #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {AdminComponent} from './admin/admin.component'; import {AdminDashboardComponent} from './admin-dashboard/admin-dashboard.component'; import {ManageCrisesComponent} from './manage-crises/manage-crises.component'; import {ManageHeroesComponent} from './manage-heroes/manage-heroes.component'; import {authGuard} from '../auth/auth.guard'; const adminRoutes: Routes = [ { path: '', component: AdminComponent, canActivate: [authGuard], children: [ { path: '', canActivateChild: [authGuard], children: [ {path: 'crises', component: ManageCrisesComponent}, {path: 'heroes', component: ManageHeroesComponent}, {path: '', component: AdminDashboardComponent}, ], }, ], }, ]; @NgModule({ imports: [RouterModule.forChild(adminRoutes)], exports: [RouterModule], }) export class AdminRoutingModule {} // #enddocregion
{ "end_byte": 1042, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-routing.module.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin-routing.module.3.ts_0_1080
// #docplaster // #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {AdminComponent} from './admin/admin.component'; import {AdminDashboardComponent} from './admin-dashboard/admin-dashboard.component'; import {ManageCrisesComponent} from './manage-crises/manage-crises.component'; import {ManageHeroesComponent} from './manage-heroes/manage-heroes.component'; import {authGuard} from '../auth/auth.guard'; // #docregion can-activate-child const adminRoutes: Routes = [ { path: 'admin', component: AdminComponent, canActivate: [authGuard], children: [ { path: '', canActivateChild: [authGuard], children: [ {path: 'crises', component: ManageCrisesComponent}, {path: 'heroes', component: ManageHeroesComponent}, {path: '', component: AdminDashboardComponent}, ], }, ], }, ]; @NgModule({ imports: [RouterModule.forChild(adminRoutes)], exports: [RouterModule], }) export class AdminRoutingModule {} // #enddocregion
{ "end_byte": 1080, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-routing.module.3.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin-routing.module.2.ts_0_1201
// #docplaster // #docregion import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; // #docregion admin-route import {authGuard} from '../auth/auth.guard'; import {AdminDashboardComponent} from './admin-dashboard/admin-dashboard.component'; import {AdminComponent} from './admin/admin.component'; import {ManageCrisesComponent} from './manage-crises/manage-crises.component'; import {ManageHeroesComponent} from './manage-heroes/manage-heroes.component'; const adminRoutes: Routes = [ { path: 'admin', component: AdminComponent, canActivate: [authGuard], // #enddocregion admin-route // #docregion admin-route children: [ { path: '', children: [ {path: 'crises', component: ManageCrisesComponent}, {path: 'heroes', component: ManageHeroesComponent}, {path: '', component: AdminDashboardComponent}, ], // #enddocregion admin-route canActivateChild: [authGuard], // #docregion admin-route }, ], }, ]; @NgModule({imports: [RouterModule.forChild(adminRoutes)], exports: [RouterModule]}) export class AdminRoutingModule {} // #enddocregion
{ "end_byte": 1201, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-routing.module.2.ts" }
angular/adev/src/content/examples/router/src/app/admin/manage-heroes/manage-heroes.component.html_0_30
<p>Manage your heroes here</p>
{ "end_byte": 30, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/manage-heroes/manage-heroes.component.html" }
angular/adev/src/content/examples/router/src/app/admin/manage-heroes/manage-heroes.component.ts_0_261
// #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-manage-heroes', templateUrl: './manage-heroes.component.html', styleUrls: ['./manage-heroes.component.css'], standalone: false, }) export class ManageHeroesComponent {}
{ "end_byte": 261, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/manage-heroes/manage-heroes.component.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin/admin.component.ts_0_230
// #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.css'], standalone: false, }) export class AdminComponent {}
{ "end_byte": 230, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin/admin.component.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin/admin.component.css_0_285
nav a { padding: 1rem; font-size: 1rem; background-color: #e8e8e8; color: #3d3d3d; } @media (min-width: 400px) { nav a { font-size: 1.2rem; } } nav a:hover { color: white; background-color: #42545C; } nav a.active { background-color: black; color: white; }
{ "end_byte": 285, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin/admin.component.css" }
angular/adev/src/content/examples/router/src/app/admin/admin/admin.component.html_0_398
<h2>Admin</h2> <nav> <a routerLink="./" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }" ariaCurrentWhenActive="page">Dashboard</a> <a routerLink="./crises" routerLinkActive="active" ariaCurrentWhenActive="page">Manage Crises</a> <a routerLink="./heroes" routerLinkActive="active" ariaCurrentWhenActive="page">Manage Heroes</a> </nav> <router-outlet></router-outlet>
{ "end_byte": 398, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin/admin.component.html" }
angular/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.html_0_206
<h3>Dashboard</h3> <p>Session ID: {{ sessionId | async }}</p> <div id="anchor"></div> <p>Token: {{ token | async }}</p> Preloaded Modules <ul> <li *ngFor="let module of modules">{{ module }}</li> </ul>
{ "end_byte": 206, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.html" }
angular/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.1.ts_0_831
// #docregion import {Component, OnInit} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {Observable} from 'rxjs'; import {map} from 'rxjs/operators'; @Component({ selector: 'app-admin-dashboard', templateUrl: './admin-dashboard.component.html', styleUrls: ['./admin-dashboard.component.css'], standalone: false, }) export class AdminDashboardComponent implements OnInit { sessionId!: Observable<string>; token!: Observable<string>; constructor(private route: ActivatedRoute) {} ngOnInit() { // Capture the session ID if available this.sessionId = this.route.queryParamMap.pipe( map((params) => params.get('session_id') || 'None'), ); // Capture the fragment if available this.token = this.route.fragment.pipe(map((fragment) => fragment || 'None')); } }
{ "end_byte": 831, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.1.ts" }
angular/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.1.html_0_19
<h3>Dashboard</h3>
{ "end_byte": 19, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.1.html" }
angular/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.ts_0_1076
// #docregion import {Component, OnInit} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {Observable} from 'rxjs'; import {map} from 'rxjs/operators'; import {SelectivePreloadingStrategyService} from '../../selective-preloading-strategy.service'; @Component({ selector: 'app-admin-dashboard', templateUrl: './admin-dashboard.component.html', styleUrls: ['./admin-dashboard.component.css'], standalone: false, }) export class AdminDashboardComponent implements OnInit { sessionId!: Observable<string>; token!: Observable<string>; modules: string[] = []; constructor( private route: ActivatedRoute, preloadStrategy: SelectivePreloadingStrategyService, ) { this.modules = preloadStrategy.preloadedModules; } ngOnInit() { // Capture the session ID if available this.sessionId = this.route.queryParamMap.pipe( map((params) => params.get('session_id') || 'None'), ); // Capture the fragment if available this.token = this.route.fragment.pipe(map((fragment) => fragment || 'None')); } }
{ "end_byte": 1076, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/admin-dashboard/admin-dashboard.component.ts" }
angular/adev/src/content/examples/router/src/app/admin/manage-crises/manage-crises.component.ts_0_261
// #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-manage-crises', templateUrl: './manage-crises.component.html', styleUrls: ['./manage-crises.component.css'], standalone: false, }) export class ManageCrisesComponent {}
{ "end_byte": 261, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/manage-crises/manage-crises.component.ts" }
angular/adev/src/content/examples/router/src/app/admin/manage-crises/manage-crises.component.html_0_30
<p>Manage your crises here</p>
{ "end_byte": 30, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/admin/manage-crises/manage-crises.component.html" }
angular/adev/src/content/examples/router/src/app/compose-message/compose-message.component.ts_0_942
// #docregion import {Component} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; @Component({ selector: 'app-compose-message', templateUrl: './compose-message.component.html', styleUrls: ['./compose-message.component.css'], standalone: false, }) export class ComposeMessageComponent { details = ''; message = ''; sending = false; constructor( private router: Router, private route: ActivatedRoute, ) {} send() { this.sending = true; this.details = 'Sending Message...'; setTimeout(() => { this.sending = false; this.closePopup(); }, 1000); } cancel() { this.closePopup(); } // #docregion closePopup closePopup() { // Providing a `null` value to the named outlet // clears the contents of the named outlet this.router.navigate([{outlets: {popup: null}}], {relativeTo: this.route.parent}); } // #enddocregion closePopup }
{ "end_byte": 942, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/compose-message/compose-message.component.ts" }
angular/adev/src/content/examples/router/src/app/compose-message/compose-message.component.css_0_95
textarea { width: 100%; margin-top: 1rem; font-size: 1.2rem; box-sizing: border-box; }
{ "end_byte": 95, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/compose-message/compose-message.component.css" }
angular/adev/src/content/examples/router/src/app/compose-message/compose-message.component.html_0_439
<!-- #docregion --> <h3>Contact Crisis Center</h3> <div *ngIf="details"> {{ details }} </div> <div> <div> <label for="message">Enter your message: </label> </div> <div> <textarea id="message" [(ngModel)]="message" rows="10" cols="35" [disabled]="sending"></textarea> </div> </div> <p *ngIf="!sending"> <button type="button" (click)="send()">Send</button> <button type="button" (click)="cancel()">Cancel</button> </p>
{ "end_byte": 439, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/compose-message/compose-message.component.html" }
angular/adev/src/content/examples/router/src/app/crisis-list/crisis-list.component.1.ts_0_282
// Initial empty version // #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-crisis-list', templateUrl: './crisis-list.component.1.html', styleUrls: ['./crisis-list.component.1.css'], standalone: false, }) export class CrisisListComponent {}
{ "end_byte": 282, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-list/crisis-list.component.1.ts" }
angular/adev/src/content/examples/router/src/app/crisis-list/crisis-list.component.1.html_0_51
<h2>CRISIS CENTER</h2> <p>Get your crisis here</p>
{ "end_byte": 51, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/crisis-list/crisis-list.component.1.html" }
angular/adev/src/content/examples/router/src/app/hero-list/hero-list.component.1.html_0_176
<!-- #docregion template --> <h2>HEROES</h2> <p>Get your heroes here</p> <!-- #enddocregion template--> <button type="button" routerLink="/sidekicks">Go to sidekicks</button>
{ "end_byte": 176, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/hero-list/hero-list.component.1.html" }
angular/adev/src/content/examples/router/src/app/hero-list/hero-list.component.1.ts_0_249
// #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-hero-list', templateUrl: './hero-list.component.1.html', styleUrls: ['./hero-list.component.1.css'], standalone: false, }) export class HeroListComponent {}
{ "end_byte": 249, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/hero-list/hero-list.component.1.ts" }
angular/adev/src/content/tutorials/home.md_0_800
# Tutorials Welcome to the Angular tutorials! These tutorials will guide you through the core concepts of the framework, and get you started building performant, scalable apps. <docs-card-container> <docs-card title="Learn Angular in your browser" link="Start coding" href="tutorials/learn-angular" imgSrc="adev/src/assets/images/learn-angular-browser.svg"> via the Playground </docs-card> <docs-card title="Build your first Angular app locally" link="Start coding" href="tutorials/first-app" imgSrc="adev/src/assets/images/learn-angular-local.svg"> via npm </docs-card> <docs-card title="Deferrable views" link="Start coding" href="tutorials/deferrable-views" imgSrc="adev/src/assets/images/ang_illustrations-04.svg"> via the Playground </docs-card> </docs-card-container>
{ "end_byte": 800, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/home.md" }
angular/adev/src/content/tutorials/README.md_0_5610
# Angular embedded docs tutorial - [Tutorial files](#tutorial-files) - [Tutorials directory structure](#tutorials-directory-structure) - [Reserved tutorials directories](#reserved-tutorials-directories) ## Tutorial files The tutorials content consists of the tutorial content, source code and configuration. ### Content: `README.md` The tutorial content must be located in a `README.md` file in the tutorial directory. Taking the `learn-angular` tutorial as an example, see: [`src/content/tutorials/learn-angular/intro/README.md`](/src/content/tutorials/learn-angular/intro/README.md) ### Configuration: `config.json` Each tutorial is defined by a `config.json`, which can have the following options: - `title`: defines the tutorial title used in the tutorial nav - `nextTutorial`: the path of the next tutorial (only in `intro/` step) - `src`: the relative path to an external directory, which defines the tutorial source code used in the embedded editor - `answerSrc`: the relative path to an external directory, which defines the tutorial answer used in the embedded editor - `openFiles`: an array of files to be open in the editor - `type`: the type denotes how the tutorial will be presented and which components are necessary for that tutorial - `cli`: a tutorial with a `cli` type will contain only the content and an interactive terminal with the Angular CLI - `editor`: used for the complete embedded editor, containing the code editor, the preview, an interactive terminal and the console with outputs from the dev server - `local`: disables the embedded editor and shows only the content - `editor-only`: a special config used for the tutorial playground and the homepage playground, which disables the content and shows only the embedded editor ### Source code The tutorial source code includes every file in the tutorial directory, except `README.md` and `config.json`. The tutorial source code has precedence over the [`common`](#common) project file, so if a file exists in both [`common`](#common) and in the tutorial directory, containing the same relative path, the tutorial file will override the [`common`](#common) file. ## Tutorials directory structure A tutorial is composed of an introduction and steps. Both the intro and each step contains its own content, config and source code. Taking the `learn-angular` tutorial as an example: ### Introduction [`src/content/tutorials/learn-angular/intro`](/src/content/tutorials/learn-angular/intro) is the introduction of the tutorial, which will live in the `/tutorials/learn-angular` route. ### Steps [`src/content/tutorials/learn-angular/steps`](/src/content/tutorials/learn-angular/steps) is the directory that contains the tutorial steps. These are some examples from the `learn-angular` tutorial: - [`learn-angular/steps/1-components-in-angular`](/src/content/tutorials/learn-angular/steps/1-components-in-angular): The route will be `/tutorials/learn-angular/components-in-angular` - [`learn-angular/steps/2-updating-the-component-class`](/src/content/tutorials/learn-angular/steps/2-updating-the-component-class): The route will be `/tutorials/learn-angular/updating-the-component-class` Each step directory must start with a number followed by a hyphen, then followed by the step pathname. - The number denotes the step, defining which will be the previous and next step within a tutorial. - The hyphen is a delimiter :). - The pathname taken from the directory name defines the step URL. ## Reserved tutorials directories ### `common` The common project is a complete Angular project that is reused by all tutorials. It contains all dependencies(`package.json`, `package-lock.json`), project configuration(`tsconfig.json`, `angular.json`) and main files to bootstrap the application(`index.html`, `main.ts`, `app.module.ts`). A common project is used for a variety of reasons: - Avoid duplication of files in tutorials. - Optimize in-app performance by requesting the common project files and dependencies only once, benefiting from the browser cache on subsequent requests. - Require a single `npm install` for all tutorials, therefore reducing the time to interactive with the tutorial when navigating different tutorials and steps. - Provide a consistent environment for all tutorials. - Allow each tutorial to focus on the specific source code for what's being taught and not on the project setup. See [`src/content/tutorials/common`](/src/content/tutorials/common) ### `playground` The playground contains the source code for the tutorials playground at `/playground`. It should not contain any content. See [`src/content/tutorials/playground`](/src/content/tutorials/playground) ### `homepage` The homepage contains the source code for the homepage playground. It should not contain any content. See [`src/content/tutorials/homepage`](/src/content/tutorials/homepage) ## Update dependencies To update the dependencies of all tutorials you can run the following script ```bash rm ./adev/src/content/tutorials/homepage/package-lock.json ./adev/src/content/tutorials/first-app/common/package-lock.json ./adev/src/content/tutorials/learn-angular/common/package-lock.json ./adev/src/content/tutorials/playground/common/package-lock.json npm i --package-lock-only --prefix ./adev/src/content/tutorials/homepage npm i --package-lock-only --prefix ./adev/src/content/tutorials/first-app/common npm i --package-lock-only --prefix ./adev/src/content/tutorials/learn-angular/common npm i --package-lock-only --prefix ./adev/src/content/tutorials/playground/common ```
{ "end_byte": 5610, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/README.md" }
angular/adev/src/content/tutorials/BUILD.bazel_0_469
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "tutorials", srcs = glob( [ "*.md", ], exclude = [ "README.md", ], ), data = [ "//adev/src/assets/images:ang_illustrations-04.svg", "//adev/src/assets/images:learn-angular-browser.svg", "//adev/src/assets/images:learn-angular-local.svg", ], visibility = ["//adev:__subpackages__"], )
{ "end_byte": 469, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/BUILD.bazel" }
angular/adev/src/content/tutorials/homepage/BUILD.bazel_0_273
load("//adev/shared-docs:index.bzl", "generate_playground") package(default_visibility = ["//adev:__subpackages__"]) filegroup( name = "files", srcs = glob( ["**/*"], ), ) generate_playground( name = "homepage", playground_srcs = ":files", )
{ "end_byte": 273, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/homepage/BUILD.bazel" }
angular/adev/src/content/tutorials/homepage/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/homepage/idx/dev.nix" }
angular/adev/src/content/tutorials/homepage/src/main.ts_0_502
import {Component} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {bootstrapApplication} from '@angular/platform-browser'; @Component({ selector: 'app-root', standalone: true, template: ` <label for="name">Name:</label> <input type="text" id="name" [(ngModel)]="name" placeholder="Enter a name here" /> <hr /> <h1>Hello {{ name }}!</h1> `, imports: [FormsModule], }) export class DemoComponent { name = ''; } bootstrapApplication(DemoComponent);
{ "end_byte": 502, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/homepage/src/main.ts" }
angular/adev/src/content/tutorials/playground/BUILD.bazel_0_260
load("//adev/shared-docs:index.bzl", "generate_playground") package(default_visibility = ["//adev:__subpackages__"]) filegroup( name = "files", srcs = glob(["**/*"]), ) generate_playground( name = "playground", playground_srcs = ":files", )
{ "end_byte": 260, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/BUILD.bazel" }
angular/adev/src/content/tutorials/playground/1-signals/src/main.ts_0_872
import {Component, signal, computed} from '@angular/core'; import {bootstrapApplication} from '@angular/platform-browser'; @Component({ selector: 'app-root', standalone: true, template: ` <h2>Cookie recipe</h2> <label> # of cookies: <input type="range" min="10" max="100" step="10" [value]="count()" (input)="update($event)" /> {{ count() }} </label> <p>Butter: {{ butter() }} cup(s)</p> <p>Sugar: {{ sugar() }} cup(s)</p> <p>Flour: {{ flour() }} cup(s)</p> `, }) export class CookieRecipe { count = signal(10); butter = computed(() => this.count() * 0.1); sugar = computed(() => this.count() * 0.05); flour = computed(() => this.count() * 0.2); update(event: Event) { const input = event.target as HTMLInputElement; this.count.set(parseInt(input.value)); } } bootstrapApplication(CookieRecipe);
{ "end_byte": 872, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/1-signals/src/main.ts" }
angular/adev/src/content/tutorials/playground/2-control-flow/src/main.ts_0_822
import {Component} from '@angular/core'; import {bootstrapApplication} from '@angular/platform-browser'; @Component({ selector: 'app-root', standalone: true, template: ` <h2>Todos</h2> <input #text /> <button (click)="add(text.value)">Add</button> @for (todo of todos; track $index) { <p> <input type="checkbox" (change)="toggle($index)" /> @if (todo.done) { <s>{{ todo.text }}</s> } @else { <span>{{ todo.text }}</span> } </p> } @empty { <p>No todos</p> } `, }) export class TodosComponent { todos: Array<{done: boolean; text: string}> = []; add(text: string) { this.todos.push({text, done: false}); } toggle(index: number) { this.todos[index].done = !this.todos[index].done; } } bootstrapApplication(TodosComponent);
{ "end_byte": 822, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/2-control-flow/src/main.ts" }
angular/adev/src/content/tutorials/playground/3-minigame/src/main.ts_0_6942
import {A11yModule} from '@angular/cdk/a11y'; import {CommonModule} from '@angular/common'; import {Component, ElementRef, ViewChild, computed, signal} from '@angular/core'; import {MatSlideToggleChange, MatSlideToggleModule} from '@angular/material/slide-toggle'; import {bootstrapApplication} from '@angular/platform-browser'; const RESULT_QUOTES = [ [ 'Not quite right!', 'You missed the mark!', 'Have you seen an angle before?', 'Your measurements are all over the place!', 'Your precision needs work!', ], ['Not too shabby.', 'Getting sharper, keep it up!', 'Not perfect, but getting better!'], [ 'Your angles are on point!', 'Your precision is unparalleled!', 'Your geometric skills are divine!', "Amazing! You're acute-y!", 'Wow! So precise!', ], ]; const CHANGING_QUOTES = [ ["I'm such a-cute-y!", "I'm a tiny slice of pi!", "You're doing great!"], ["I'm wide open!", 'Keep going!', 'Wow!', 'Wheee!!'], ["I'm so obtuse!", 'The bigger the better!', "Life's too short for right angles!", 'Whoa!'], ]; function getChangingQuote(rotateValue: number): string { let possibleQuotes = CHANGING_QUOTES[1]; if (rotateValue < 110) { possibleQuotes = CHANGING_QUOTES[0]; } else if (rotateValue >= 230) { possibleQuotes = CHANGING_QUOTES[2]; } const randomQuoteIndex = Math.floor(Math.random() * possibleQuotes.length); return possibleQuotes[randomQuoteIndex]; } function getResultQuote(accuracy: number) { let possibleQuotes = RESULT_QUOTES[1]; if (accuracy < 50) { possibleQuotes = RESULT_QUOTES[0]; } else if (accuracy >= 85) { possibleQuotes = RESULT_QUOTES[2]; } let randomQuoteIndex = Math.floor(Math.random() * possibleQuotes.length); return possibleQuotes[randomQuoteIndex]; } @Component({ selector: 'app-root', standalone: true, imports: [CommonModule, MatSlideToggleModule, A11yModule], styleUrl: 'game.css', templateUrl: 'game.html', }) export class PlaygroundComponent { protected readonly isGuessModalOpen = signal(false); protected readonly isAccessiblePanelOpen = signal(false); protected readonly rotateVal = signal(40); protected readonly goal = signal(85); protected readonly animatedAccuracy = signal(0); protected readonly gameStats = signal({ level: 0, totalAccuracy: 0, }); protected readonly resultQuote = signal(''); private isDragging = false; private currentInteractions: {lastChangedAt: number; face: number; quote: string} = { lastChangedAt: 75, face: 0, quote: "Hi, I'm NG the Angle!", }; @ViewChild('staticArrow') staticArrow!: ElementRef; protected readonly totalAccuracyPercentage = computed(() => { const {level, totalAccuracy} = this.gameStats(); if (level === 0) { return 0; } return totalAccuracy / level; }); protected readonly updatedInteractions = computed(() => { if ( this.rotateVal() > 75 && Math.abs(this.rotateVal() - this.currentInteractions.lastChangedAt) > 70 && Math.random() > 0.5 ) { this.currentInteractions = { lastChangedAt: this.rotateVal(), face: Math.floor(Math.random() * 6), quote: getChangingQuote(this.rotateVal()), }; } return this.currentInteractions; }); constructor() { this.resetGame(); } resetGame() { this.goal.set(Math.floor(Math.random() * 360)); this.rotateVal.set(40); } getRotation() { return `rotate(${this.rotateVal()}deg)`; } getIndicatorStyle() { return 0.487 * this.rotateVal() - 179.5; } getIndicatorRotation() { return `rotate(${253 + this.rotateVal()}deg)`; } mouseDown() { this.isDragging = true; } stopDragging() { this.isDragging = false; } mouseMove(e: MouseEvent) { const vh30 = 0.3 * document.documentElement.clientHeight; if (!this.isDragging) return; let pointX = e.pageX - (this.staticArrow.nativeElement.offsetLeft + 2.5); let pointY = e.pageY - (this.staticArrow.nativeElement.offsetTop + vh30); let calculatedAngle = 0; if (pointX >= 0 && pointY < 0) { calculatedAngle = 90 - (Math.atan2(Math.abs(pointY), pointX) * 180) / Math.PI; } else if (pointX >= 0 && pointY >= 0) { calculatedAngle = 90 + (Math.atan2(pointY, pointX) * 180) / Math.PI; } else if (pointX < 0 && pointY >= 0) { calculatedAngle = 270 - (Math.atan2(pointY, Math.abs(pointX)) * 180) / Math.PI; } else { calculatedAngle = 270 + (Math.atan2(Math.abs(pointY), Math.abs(pointX)) * 180) / Math.PI; } this.rotateVal.set(calculatedAngle); } adjustAngle(degreeChange: number) { this.rotateVal.update((x) => x + degreeChange < 0 ? 360 + (x + degreeChange) : (x + degreeChange) % 360, ); } touchMove(e: Event) { let firstTouch = (e as TouchEvent).touches[0]; if (firstTouch) { this.mouseMove({pageX: firstTouch.pageX, pageY: firstTouch.pageY} as MouseEvent); } } guess() { this.isGuessModalOpen.set(true); const calcAcc = Math.abs(100 - (Math.abs(this.goal() - this.rotateVal()) / 180) * 100); this.resultQuote.set(getResultQuote(calcAcc)); this.animatedAccuracy.set(calcAcc > 20 ? calcAcc - 20 : 0); this.powerUpAccuracy(calcAcc); this.gameStats.update(({level, totalAccuracy}) => ({ level: level + 1, totalAccuracy: totalAccuracy + calcAcc, })); } powerUpAccuracy(finalAcc: number) { if (this.animatedAccuracy() >= finalAcc) return; let difference = finalAcc - this.animatedAccuracy(); if (difference > 20) { this.animatedAccuracy.update((x) => x + 10.52); setTimeout(() => this.powerUpAccuracy(finalAcc), 30); } else if (difference > 4) { this.animatedAccuracy.update((x) => x + 3.31); setTimeout(() => this.powerUpAccuracy(finalAcc), 40); } else if (difference > 0.5) { this.animatedAccuracy.update((x) => x + 0.49); setTimeout(() => this.powerUpAccuracy(finalAcc), 50); } else if (difference >= 0.1) { this.animatedAccuracy.update((x) => x + 0.1); setTimeout(() => this.powerUpAccuracy(finalAcc), 100); } else { this.animatedAccuracy.update((x) => x + 0.01); setTimeout(() => this.powerUpAccuracy(finalAcc), 100); } } close() { this.isGuessModalOpen.set(false); this.resetGame(); } getText() { const roundedAcc = Math.floor(this.totalAccuracyPercentage() * 10) / 10; let emojiAccuracy = ''; for (let i = 0; i < 5; i++) { emojiAccuracy += roundedAcc >= 20 * (i + 1) ? '🟩' : '⬜️'; } return encodeURIComponent( `📐 ${emojiAccuracy} \n My angles are ${roundedAcc}% accurate on level ${ this.gameStats().level }. \n\nHow @Angular are you? \nhttps://angular.dev/playground`, ); } toggleA11yControls(event: MatSlideToggleChange) { this.isAccessiblePanelOpen.set(event.checked); } } bootstrapApplication(PlaygroundComponent);
{ "end_byte": 6942, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/3-minigame/src/main.ts" }
angular/adev/src/content/tutorials/playground/3-minigame/src/styles.css_0_694
/* You can add global styles to this file, and also import other style files */ @import "@angular/material/prebuilt-themes/indigo-pink.css"; * { margin: 0; padding: 0; } html, body { height: 100%; } body { font-family: 'Be Vietnam Pro', sans-serif; } :root { --bright-blue: oklch(51.01% 0.274 263.83); --indigo-blue: oklch(51.64% 0.229 281.65); --electric-violet: oklch(53.18% 0.28 296.97); --french-violet: oklch(47.66% 0.246 305.88); --vivid-pink: oklch(69.02% 0.277 332.77); --hot-pink: oklch(59.91% 0.239 8.14); --hot-red: oklch(61.42% 0.238 15.34); --orange-red: oklch(63.32% 0.24 31.68); --light-pink: color-mix(in srgb, var(--vivid-pink) 10%, white 80%); }
{ "end_byte": 694, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/3-minigame/src/styles.css" }
angular/adev/src/content/tutorials/playground/3-minigame/src/game.css_0_5441
.wrapper { height: 100%; width: 100%; max-width: 1000px; margin: auto; display: flex; justify-content: flex-end; align-items: center; } .col { width: 100%; display: flex; flex-direction: column; justify-content: space-between; align-items: center; } .overall-stats { display: flex; flex-direction: column; align-items: center; padding: 1rem; font-size: 1.3rem; user-select: none; } #goal { font-size: 2rem; } #quote { margin-top: 10px; opacity: 0; transition: all 0.3s ease; } #quote.show { opacity: 1; } .gradient-button { text-decoration: none; color: black; margin: 8px; position: relative; cursor: pointer; font-size: 1rem; border: none; font-weight: 600; width: fit-content; height: fit-content; padding-block: 0; padding-inline: 0; } .gradient-button span:nth-of-type(1) { position: absolute; border-radius: 0.25rem; height: 100%; width: 100%; left: 0; top: 0; background: linear-gradient(90deg, var(--orange-red) 0%, var(--vivid-pink) 50%, var(--electric-violet) 100%); } .gradient-button span:nth-of-type(2) { position: relative; padding: 0.75rem 1rem; background: white; margin: 1px; border-radius: 0.2rem; transition: all .3s ease; opacity: 1; display: flex; align-items: center; } .gradient-button:enabled:hover span:nth-of-type(2), .gradient-button:enabled:focus span:nth-of-type(2) { opacity: 0.9; } a.gradient-button:hover span:nth-of-type(2), a.gradient-button:focus span:nth-of-type(2) { opacity: 0.9; } .gradient-button:disabled { cursor: not-allowed; color: #969696; } .gradient-button img { display: inline; height: 0.8rem; margin-left: 4px; } #angle { height: 60vh; width: 60vh; display: flex; flex-direction: column; justify-content: flex-start; align-items: center; padding: 10px; margin: 10px; } .grabbable { height: 30vh; width: 25px; position: absolute; cursor: pointer; transform-origin: bottom center; } .arrow { height: 30vh; width: 4px; background-color: black; position: absolute; } .arrow::before, .arrow::after { content: ''; position: absolute; top: -4px; left: -6px; height: 20px; transform: rotate(45deg); width: 4px; background-color: black; border-radius: 0px 0px 5px 5px; } .arrow::after { left: 6px; transform: rotate(-45deg); } #static > div.center { height: 4px; width: 4px; background-color: black; position: absolute; bottom: -2px; border-radius: 100%; } #static > div.svg { height: 75px; width: 75px; position: absolute; bottom: -37.5px; left: -35.5px; transform-origin: center; transform: rotate(294deg); } #static svg .svg-arrow { fill: none; stroke-linecap: round; stroke-miterlimit: 10; stroke-width: 3px; } #static svg path { stroke-dasharray: 180; } #moving { transform-origin: bottom center; left: calc(50% - 2px); } .face svg { position: absolute; height: 13vh; width: 13vh; bottom: 2vh; left: 4vh; opacity: 0; transition: all 0.2s ease; } .face svg.show { opacity: 1; } .face svg .b { stroke-width: 6px; } .face svg .b, .c { stroke-miterlimit: 10; } .face svg .b, .c, .d { fill: none; stroke: #000; stroke-linecap: round; } .face svg .e { fill: #fff; } .face svg .c, .d { stroke-width: 7px; } .face svg .d { stroke-linejoin: round; } #result { background-color: white; border-radius: 8px; border: 1px solid #f6f6f6; box-shadow: 0 3px 14px 0 rgba(0,0,0,.2); position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 50%; display: flex; flex-direction: column; justify-content: space-around; align-items: center; padding: 2rem; z-index: 10; } svg.personified { height: 125px; } .personified .g { fill: #fff; } .personified .h { stroke-miterlimit: 10; stroke-width: 4px; } .personified .h, .personified .i { fill: none; stroke: #000; stroke-linecap: round; } .personified .i { stroke-linejoin: round; stroke-width: 3px; } #close { border: none; background: none; position: absolute; top: 8px; right: 8px; font-size: 19px; cursor: pointer; } .result-stats, .result-buttons { display: flex; width: 100%; justify-content: center; } .result-stats > * { margin: 4px 16px; } .result-buttons { margin-top: 16px; } .accuracy { font-weight: 700; margin: 1rem; } .accuracy span { font-size: 4rem; margin-right: 6px; } #copy { display: none; } .accessibility { position: fixed; left: 10px; bottom: 10px; } #toggle { margin-top: 8px; } .accessibility button { width: 2rem; height: 2rem; font-size: 1rem; border: 2px solid var(--electric-violet); border-radius: 4px; cursor: pointer; margin: 0 4px; background-color: #fff; transition: all 0.3s ease; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.3607843137); } .accessibility button:focus:enabled, .accessibility button:hover:enabled { background-color: #e8dbf4; } .accessibility button:disabled { cursor: not-allowed; background-color: #eee; } @media screen and (max-width: 650px) { .wrapper { flex-direction: column-reverse; align-items: center; } .overall-stats { align-items: center; margin-bottom: 16px; } #result { box-sizing: border-box; min-width: auto; height: 100%; width: 100%; padding: 20px; top: 0; left: 0; border-radius: 0; transform: none; } }
{ "end_byte": 5441, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/3-minigame/src/game.css" }
angular/adev/src/content/tutorials/playground/3-minigame/src/game.html_0_4971
<div class="wrapper"> <div class="col"> <h1>Goal: {{ goal() }}º</h1> <div id="quote" [class.show]="rotateVal() >= 74">"{{ updatedInteractions().quote }}"</div> <div id="angle" (mouseup)="stopDragging()" (mouseleave)="stopDragging()" (mousemove)="mouseMove($event)" (touchmove)="touchMove($event)" (touchend)="stopDragging()" (touchcanceled)="stopDragging()" > <div class="arrow" id="static" #staticArrow> <div class="center"></div> @if(rotateVal() >= 20) { <div class="svg" [style.transform]="getIndicatorRotation()"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 75 75"> <defs> <linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" stop-color="var(--orange-red)" /> <stop offset="50%" stop-color="var(--vivid-pink)" /> <stop offset="100%" stop-color="var(--electric-violet)" /> </linearGradient> </defs> <path [style.stroke-dashoffset]="getIndicatorStyle()" class="svg-arrow" stroke="url(#gradient)" d="m64.37,45.4c-3.41,11.62-14.15,20.1-26.87,20.1-15.46,0-28-12.54-28-28s12.54-28,28-28,28,12.54,28,28" /> <polyline class="svg-arrow" stroke="url(#gradient)" points="69.63 36.05 65.29 40.39 60.96 36.05" /> </svg> </div> } <div class="face"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 103.41 84.33" [class.show]="rotateVal() >= 74"> @switch(updatedInteractions().face) { @case(0) { <g> <path class="c" d="m65.65,55.83v11c0,7.73-6.27,14-14,14h0c-7.73,0-14-6.27-14-14v-11"/> <line class="c" x1="51.52" y1="65.83" x2="51.65" y2="57.06"/> <path class="c" d="m19.8,44.06c7.26,7.89,18.83,13,31.85,13s24.59-5.11,31.85-13"/> <path class="b" d="m3,14.33c3.35-5.71,9.55-9.54,16.65-9.54,6.66,0,12.53,3.37,16,8.5"/> <path class="b" d="m100.3,14.33c-3.35-5.71-9.55-9.54-16.65-9.54-6.66,0-12.53,3.37-16,8.5"/> </g> } @case(1) { <g> <path class="d" d="m22.11,48.83c-.08.65-.14,1.3-.14,1.97,0,11.94,13.37,21.62,29.87,21.62s29.87-9.68,29.87-21.62c0-.66-.06-1.32-.14-1.97H22.11Z"/> <circle cx="19.26" cy="12.56" r="12.37"/> <circle cx="84.25" cy="12.56" r="12.37"/> <circle class="e" cx="14.86" cy="8.94" r="4.24"/> <circle class="e" cx="80.29" cy="8.76" r="4.24"/> </g> } @case(2) { <g> <circle cx="19.2" cy="12.72" r="12.37"/> <circle cx="84.19" cy="12.72" r="12.37"/> <circle class="e" cx="14.8" cy="9.09" r="4.24"/> <circle class="e" cx="80.22" cy="8.92" r="4.24"/> <path class="c" d="m19.45,44.33c7.26,7.89,18.83,13,31.85,13s24.59-5.11,31.85-13"/> </g> } @case(3) { <g> <path class="b" d="m3.11,14.33c3.35-5.71,9.55-9.54,16.65-9.54,6.66,0,12.53,3.37,16,8.5"/> <path class="b" d="m100.41,14.33c-3.35-5.71-9.55-9.54-16.65-9.54-6.66,0-12.53,3.37-16,8.5"/> <path class="c" d="m19.91,44.06c7.26,7.89,18.83,13,31.85,13s24.59-5.11,31.85-13"/> </g> } @case(4) { <g> <circle cx="19.26" cy="12.5" r="12.37"/> <circle class="e" cx="14.86" cy="8.88" r="4.24"/> <path class="c" d="m19.51,44.11c7.26,7.89,18.83,13,31.85,13s24.59-5.11,31.85-13"/> <path class="b" d="m100.08,14.33c-3.35-5.71-9.55-9.54-16.65-9.54-6.66,0-12.53,3.37-16,8.5"/> </g> } @default { <g> <circle cx="19.14" cy="12.44" r="12.37"/> <circle cx="84.13" cy="12.44" r="12.37"/> <circle class="e" cx="14.74" cy="8.82" r="4.24"/> <circle class="e" cx="80.17" cy="8.64" r="4.24"/> <circle class="b" cx="52.02" cy="53.33" r="14"/> </g> } } </svg> </div> </div> <div class="grabbable" [style.transform]="getRotation()" (mousedown)="mouseDown()" (touchstart)="mouseDown()" > <div class="arrow" id="moving"></div> </div> </div> </div> <div class="col"> <div class="overall-stats"> <h4>level: {{ gameStats().level + 1 }}</h4> <h4> accuracy: {{ totalAccuracyPercentage() > 0 ? (totalAccuracyPercentage() | number : '1.1-1') + '%' : '??' }} </h4> <button id="guess" class="gradient-button" (click)="guess()" [disabled]="isGuessModalOpen()"><span></span><span>guess</span></button> </div> </div> @if(isGuessModalOpen()) {
{ "end_byte": 4971, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/3-minigame/src/game.html" }
angular/adev/src/content/tutorials/playground/3-minigame/src/game.html_4976_9162
dialog id="result" cdkTrapFocus> <button id="close" (click)="close()">X</button> <div class="result-stats"> <h2>goal: {{ goal() }}º</h2> <h2>actual: {{ rotateVal() | number : '1.1-1' }}º</h2> </div> <h2 class="accuracy"> <span>{{ animatedAccuracy() | number : '1.1-1' }}%</span> accurate </h2> <svg class="personified" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 119.07 114.91"> <g> <polyline class="i" points="1.5 103.62 56.44 1.5 40.73 8.68"/> <line class="i" x1="59.1" y1="18.56" x2="56.44" y2="1.5"/> <polyline class="i" points="1.61 103.6 117.57 102.9 103.74 92.56"/> <line class="i" x1="103.86" y1="113.41" x2="117.57" y2="102.9"/> <path class="i" d="m12.97,84.22c6.4,4.04,10.47,11.28,10.2,19.25"/> </g> @if(animatedAccuracy() > 95) { <g> <path class="i" d="m52.68,72.99c-.04.35-.07.71-.07,1.07,0,6.5,7.28,11.77,16.26,11.77s16.26-5.27,16.26-11.77c0-.36-.03-.72-.07-1.07h-32.37Z"/> <circle cx="51.13" cy="53.25" r="6.73"/> <circle cx="86.5" cy="53.25" r="6.73"/> <circle class="g" cx="48.73" cy="51.28" r="2.31"/> <circle class="g" cx="84.35" cy="51.18" r="2.31"/> </g> } @else if (animatedAccuracy() > 80) { <g> <path class="h" d="m52.59,70.26c3.95,4.3,10.25,7.08,17.34,7.08s13.38-2.78,17.34-7.08"/> <path class="h" d="m43.44,54.08c1.82-3.11,5.2-5.19,9.06-5.19,3.62,0,6.82,1.84,8.71,4.63"/> <path class="h" d="m96.41,54.08c-1.82-3.11-5.2-5.19-9.06-5.19-3.62,0-6.82,1.84-8.71,4.63"/> </g> } @else if (animatedAccuracy() > 60) { <g> <path class="h" d="m77.38,76.81v5.99c0,4.21-3.41,7.62-7.62,7.62h0c-4.21,0-7.62-3.41-7.62-7.62v-5.99"/> <line class="h" x1="69.69" y1="82.25" x2="69.76" y2="77.47"/> <path class="h" d="m52.42,70.4c3.95,4.3,10.25,7.08,17.34,7.08s13.38-2.78,17.34-7.08"/> <path class="h" d="m43.28,54.21c1.82-3.11,5.2-5.19,9.06-5.19,3.62,0,6.82,1.84,8.71,4.63"/> <path class="h" d="m96.24,54.21c-1.82-3.11-5.2-5.19-9.06-5.19-3.62,0-6.82,1.84-8.71,4.63"/> </g> } @else if (animatedAccuracy() > 40) { <g> <circle cx="51.55" cy="53.15" r="6.73"/> <circle cx="86.92" cy="53.15" r="6.73"/> <circle class="g" cx="49.15" cy="51.17" r="2.31"/> <circle class="g" cx="84.77" cy="51.08" r="2.31"/> <line class="h" x1="61.21" y1="76.81" x2="78.15" y2="76.81"/> </g> } @else { <g> <circle cx="51.55" cy="53.12" r="6.73"/> <circle cx="86.92" cy="53.12" r="6.73"/> <circle class="g" cx="49.15" cy="51.14" r="2.31"/> <circle class="g" cx="84.77" cy="51.05" r="2.31"/> <path class="h" d="m84.01,81.41c-2.37-5.86-8.11-10-14.83-10s-12.45,4.14-14.83,10"/> </g> } </svg> <div>"{{ resultQuote() }}"</div> <div class="result-buttons"> <button (click)="close()" class="gradient-button"><span></span><span>again?</span></button> <a target="_blank" class="gradient-button" [href]="'https://twitter.com/intent/tweet?text=' + getText()"><span></span><span>share<img src="assets/share.svg" aria-hidden="true"></span></a> </div> </dialog> } <div class="accessibility"> @if(isAccessiblePanelOpen()) { <div> <button [disabled]="isGuessModalOpen()" (click)="adjustAngle(-25)" aria-label="decrease angle a lot">--</button> <button [disabled]="isGuessModalOpen()" (click)="adjustAngle(-5)" aria-label="decrease angle a little">-</button> <button [disabled]="isGuessModalOpen()" (click)="adjustAngle(5)" aria-label="increase angle a little">+</button> <button [disabled]="isGuessModalOpen()" (click)="adjustAngle(25)" aria-label="increase angle a lot">++</button> </div> } <mat-slide-toggle [disabled]="isGuessModalOpen()" id="toggle" color="primary" (change)="toggleA11yControls($event)">Show Accessible Controls</mat-slide-toggle> </div> </div>
{ "end_byte": 9162, "start_byte": 4976, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/3-minigame/src/game.html" }
angular/adev/src/content/tutorials/playground/3-minigame/src/assets/share.svg_0_269
<svg width="300" height="300.251" version="1.1" xmlns="http://www.w3.org/2000/svg"> <path fill="#000" d="M178.57 127.15 290.27 0h-26.46l-97.03 110.38L89.34 0H0l117.13 166.93L0 300.25h26.46l102.4-116.59 81.8 116.59h89.34M36.01 19.54H76.66l187.13 262.13h-40.66"/> </svg>
{ "end_byte": 269, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/3-minigame/src/assets/share.svg" }
angular/adev/src/content/tutorials/playground/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/playground/common/idx/dev.nix" }
angular/adev/src/content/tutorials/playground/0-hello-world/src/main.ts_0_282
import {Component} from '@angular/core'; import {bootstrapApplication} from '@angular/platform-browser'; @Component({ selector: 'app-root', standalone: true, template: ` Hello world! `, }) export class PlaygroundComponent {} bootstrapApplication(PlaygroundComponent);
{ "end_byte": 282, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/playground/0-hello-world/src/main.ts" }
angular/adev/src/content/tutorials/first-app/BUILD.bazel_0_437
load("//adev/shared-docs:index.bzl", "generate_guides", "generate_tutorial") package(default_visibility = ["//adev:__subpackages__"]) generate_guides( name = "first-app-guides", srcs = glob(["**/*.md"]), data = [ ":files", ], ) filegroup( name = "files", srcs = glob( ["**/*"], exclude = ["**/*.md"], ), ) generate_tutorial( name = "first-app", tutorial_srcs = ":files", )
{ "end_byte": 437, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/BUILD.bazel" }
angular/adev/src/content/tutorials/first-app/intro/README.md_0_3673
# Build your first Angular app This tutorial consists of lessons that introduce the Angular concepts you need to know to start coding in Angular. You can do as many or as few as you would like and you can do them in any order. HELPFUL: Prefer video? We also have a full [YouTube course](https://youtube.com/playlist?list=PL1w1q3fL4pmj9k1FrJ3Pe91EPub2_h4jF&si=1q9889ulHp8VZ0e7) for this tutorial! <docs-video src="https://www.youtube.com/embed/xAT0lHYhHMY?si=cKUW_MGn3MesFT7o"/> ## Before you start For the best experience with this tutorial, review these requirements to make sure you have what you need to be successful. ### Your experience The lessons in this tutorial assume that you have experience with the following: 1. Created an HTML web page by editing the HTML directly. 1. Programmed web site content in JavaScript. 1. Read Cascading Style Sheet (CSS) content and understand how selectors are used. 1. Used command-line instructions to perform tasks on your computer. ### Your equipment These lessons can be completed using a local installation of the Angular tools or in our embedded editor. Local Angular development can be completed on Windows, MacOS or Linux based systems. Note: Look for alerts like this one, which call out steps that may only be for your local editor. ## Conceptual preview of your first Angular app The lessons in this tutorial create an Angular app that lists houses for rent and shows the details of individual houses. This app uses features that are common to many Angular apps. <img alt="Output of homes landing page" src="assets/images/tutorials/first-app/homes-app-landing-page.png"> ## Local development environment Note: This step is only for your local environment! Perform these steps in a command-line tool on the computer you want to use for this tutorial. <docs-workflow> <docs-step title="Identify the version of `node.js` that Angular requires"> Angular requires an active LTS or maintenance LTS version of Node. Let's confirm your version of `node.js`. For information about specific version requirements, see the engines property in the [package.json file](https://unpkg.com/browse/@angular/[email protected]/package.json). From a **Terminal** window: 1. Run the following command: `node --version` 1. Confirm that the version number displayed meets the requirements. </docs-step> <docs-step title="Install the correct version of `node.js` for Angular"> If you do not have a version of `node.js` installed, please follow the [directions for installation on nodejs.org](https://nodejs.org/en/download/) </docs-step> <docs-step title="Install the latest version of Angular"> With `node.js` and `npm` installed, the next step is to install the [Angular CLI](tools/cli) which provides tooling for effective Angular development. From a **Terminal** window run the following command: `npm install -g @angular/cli`. </docs-step> <docs-step title="Install integrated development environment (IDE)"> You are free to use any tool you prefer to build apps with Angular. We recommend the following: 1. [Visual Studio Code](https://code.visualstudio.com/) 2. As an optional, but recommended step you can further improve your developer experience by installing the [Angular Language Service](https://marketplace.visualstudio.com/items?itemName=Angular.ng-template) </docs-step> </docs-workflow> For more information about the topics covered in this lesson, visit: <docs-pill-row> <docs-pill href="/overview" title="What is Angular"/> <docs-pill href="/tools/cli/setup-local" title="Setting up the local environment and workspace"/> <docs-pill href="/cli" title="Angular CLI Reference"/> </docs-pill-row>
{ "end_byte": 3673, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/intro/README.md" }
angular/adev/src/content/tutorials/first-app/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/first-app/common/idx/dev.nix" }
angular/adev/src/content/tutorials/first-app/steps/02-HomeComponent/README.md_0_5867
# Create Home component This tutorial lesson demonstrates how to create a new [component](guide/components) for your Angular app. <docs-video src="https://www.youtube.com/embed/R0nRX8jD2D0?si=OMVaw71EIa44yIOJ"/> ## What you'll learn Your app has a new component: `HomeComponent`. ## Conceptual preview of Angular components Angular apps are built around components, which are Angular's building blocks. Components contain the code, HTML layout, and CSS style information that provide the function and appearance of an element in the app. In Angular, components can contain other components. An app's functions and appearance can be divided and partitioned into components. In Angular, components have metadata that define its properties. When you create your `HomeComponent`, you use these properties: * `selector`: to describe how Angular refers to the component in templates. * `standalone`: to describe whether the component requires a `NgModule`. * `imports`: to describe the component's dependencies. * `template`: to describe the component's HTML markup and layout. * `styleUrls`: to list the URLs of the CSS files that the component uses in an array. <docs-pill-row> <docs-pill href="api/core/Component" title="Learn more about Components"/> </docs-pill-row> <docs-workflow> <docs-step title="Create the `HomeComponent`"> In this step, you create a new component for your app. In the **Terminal** pane of your IDE: 1. In your project directory, navigate to the `first-app` directory. 1. Run this command to create a new `HomeComponent` <docs-code language="shell"> ng generate component home </docs-code> 1. Run this command to build and serve your app. Note: This step is only for your local environment! <docs-code language="shell"> ng serve </docs-code> 1. Open a browser and navigate to `http://localhost:4200` to find the application. 1. Confirm that the app builds without error. HELPFUL: It should render the same as it did in the previous lesson because even though you added a new component, you haven't included it in any of the app's templates, yet. 1. Leave `ng serve` running as you complete the next steps. </docs-step> <docs-step title="Add the new component to your app's layout"> In this step, you add the new component, `HomeComponent` to your app's root component, `AppComponent`, so that it displays in your app's layout. In the **Edit** pane of your IDE: 1. Open `app.component.ts` in the editor. 1. In `app.component.ts`, import `HomeComponent` by adding this line to the file level imports. <docs-code header="Import HomeComponent in src/app/app.component.ts" path="adev/src/content/tutorials/first-app/steps/03-HousingLocation/src/app/app.component.ts" visibleLines="[2]"/> 1. In `app.component.ts`, in `@Component`, update the `imports` array property and add `HomeComponent`. <docs-code header="Replace in src/app/app.component.ts" path="adev/src/content/tutorials/first-app/steps/03-HousingLocation/src/app/app.component.ts" visibleLines="[7]"/> 1. In `app.component.ts`, in `@Component`, update the `template` property to include the following HTML code. <docs-code header="Replace in src/app/app.component.ts" path="adev/src/content/tutorials/first-app/steps/03-HousingLocation/src/app/app.component.ts" visibleLines="[8,17]"/> 1. Save your changes to `app.component.ts`. 1. If `ng serve` is running, the app should update. If `ng serve` is not running, start it again. *Hello world* in your app should change to *home works!* from the `HomeComponent`. 1. Check the running app in the browser and confirm that the app has been updated. <img alt="browser frame of page displaying the text 'home works!'" src="assets/images/tutorials/first-app/homes-app-lesson-02-step-2.png"> </docs-step> <docs-step title="Add features to `HomeComponent`"> In this step you add features to `HomeComponent`. In the previous step, you added the default `HomeComponent` to your app's template so its default HTML appeared in the app. In this step, you add a search filter and button that is used in a later lesson. For now, that's all that `HomeComponent` has. Note that, this step just adds the search elements to the layout without any functionality, yet. In the **Edit** pane of your IDE: 1. In the `first-app` directory, open `home.component.ts` in the editor. 1. In `home.component.ts`, in `@Component`, update the `template` property with this code. <docs-code header="Replace in src/app/home/home.component.ts" path="adev/src/content/tutorials/first-app/steps/03-HousingLocation/src/app/home/home.component.ts" visibleLines="[8,15]"/> 1. Next, open `home.component.css` in the editor and update the content with these styles. Note: In the browser, these can go in `src/app/home/home.component.ts` in the `styles` array. <docs-code header="Replace in src/app/home/home.component.css" path="adev/src/content/tutorials/first-app/steps/03-HousingLocation/src/app/home/home.component.css"/> 1. Confirm that the app builds without error. You should find the filter query box and button in your app and they should be styled. Correct any errors before you continue to the next step. <img alt="browser frame of homes-app displaying logo, filter text input box and search button" src="assets/images/tutorials/first-app/homes-app-lesson-02-step-3.png"> </docs-step> </docs-workflow> Summary: In this lesson, you created a new component for your app and gave it a filter edit control and button. For more information about the topics covered in this lesson, visit: <docs-pill-row> <docs-pill href="cli/generate/component" title="`ng generate component`"/> <docs-pill href="api/core/Component" title="`Component` reference"/> <docs-pill href="guide/components" title="Angular components overview"/> </docs-pill-row>
{ "end_byte": 5867, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/tutorials/first-app/steps/02-HomeComponent/README.md" }
angular/adev/src/content/tutorials/first-app/steps/02-HomeComponent/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/02-HomeComponent/src/index.html" }