1283 lines
38 KiB
HTML
1283 lines
38 KiB
HTML
<html lang="en"><head></head><body>
|
|
<form id="mainForm" method="post" action="https://run.stackblitz.com/api/angular/v1?file=src/app/hero.service.ts" target="_self"><input type="hidden" name="files[src/app/app-routing.module.ts]" value="import { NgModule } from '@angular/core';
|
|
import { RouterModule, Routes } from '@angular/router';
|
|
|
|
import { DashboardComponent } from './dashboard/dashboard.component';
|
|
import { HeroesComponent } from './heroes/heroes.component';
|
|
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
|
|
|
|
const routes: Routes = [
|
|
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
|
|
{ path: 'dashboard', component: DashboardComponent },
|
|
{ path: 'detail/:id', component: HeroDetailComponent },
|
|
{ path: 'heroes', component: HeroesComponent }
|
|
];
|
|
|
|
@NgModule({
|
|
imports: [ RouterModule.forRoot(routes) ],
|
|
exports: [ RouterModule ]
|
|
})
|
|
export class AppRoutingModule {}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/app.component.ts]" value="import { Component } from '@angular/core';
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.css']
|
|
})
|
|
export class AppComponent {
|
|
title = 'Tour of Heroes';
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/app.module.ts]" value="import { NgModule } from '@angular/core';
|
|
import { BrowserModule } from '@angular/platform-browser';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { HttpClientModule } from '@angular/common/http';
|
|
|
|
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
|
|
import { InMemoryDataService } from './in-memory-data.service';
|
|
|
|
import { AppRoutingModule } from './app-routing.module';
|
|
|
|
import { AppComponent } from './app.component';
|
|
import { DashboardComponent } from './dashboard/dashboard.component';
|
|
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
|
|
import { HeroesComponent } from './heroes/heroes.component';
|
|
import { HeroSearchComponent } from './hero-search/hero-search.component';
|
|
import { MessagesComponent } from './messages/messages.component';
|
|
|
|
@NgModule({
|
|
imports: [
|
|
BrowserModule,
|
|
FormsModule,
|
|
AppRoutingModule,
|
|
HttpClientModule,
|
|
|
|
// The HttpClientInMemoryWebApiModule module intercepts HTTP requests
|
|
// and returns simulated server responses.
|
|
// Remove it when a real server is ready to receive requests.
|
|
HttpClientInMemoryWebApiModule.forRoot(
|
|
InMemoryDataService, { dataEncapsulation: false }
|
|
)
|
|
],
|
|
declarations: [
|
|
AppComponent,
|
|
DashboardComponent,
|
|
HeroesComponent,
|
|
HeroDetailComponent,
|
|
MessagesComponent,
|
|
HeroSearchComponent
|
|
],
|
|
bootstrap: [ AppComponent ]
|
|
})
|
|
export class AppModule { }
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/dashboard/dashboard.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
import { Hero } from '../hero';
|
|
import { HeroService } from '../hero.service';
|
|
|
|
@Component({
|
|
selector: 'app-dashboard',
|
|
templateUrl: './dashboard.component.html',
|
|
styleUrls: [ './dashboard.component.css' ]
|
|
})
|
|
export class DashboardComponent implements OnInit {
|
|
heroes: Hero[] = [];
|
|
|
|
constructor(private heroService: HeroService) { }
|
|
|
|
ngOnInit() {
|
|
this.getHeroes();
|
|
}
|
|
|
|
getHeroes(): void {
|
|
this.heroService.getHeroes()
|
|
.subscribe(heroes => this.heroes = heroes.slice(1, 5));
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/hero-detail/hero-detail.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { Location } from '@angular/common';
|
|
|
|
import { Hero } from '../hero';
|
|
import { HeroService } from '../hero.service';
|
|
|
|
@Component({
|
|
selector: 'app-hero-detail',
|
|
templateUrl: './hero-detail.component.html',
|
|
styleUrls: [ './hero-detail.component.css' ]
|
|
})
|
|
export class HeroDetailComponent implements OnInit {
|
|
hero: Hero;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private heroService: HeroService,
|
|
private location: Location
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
this.getHero();
|
|
}
|
|
|
|
getHero(): void {
|
|
const id = +this.route.snapshot.paramMap.get('id');
|
|
this.heroService.getHero(id)
|
|
.subscribe(hero => this.hero = hero);
|
|
}
|
|
|
|
goBack(): void {
|
|
this.location.back();
|
|
}
|
|
|
|
save(): void {
|
|
this.heroService.updateHero(this.hero)
|
|
.subscribe(() => this.goBack());
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/hero-search/hero-search.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Observable, Subject } from 'rxjs';
|
|
|
|
import {
|
|
debounceTime, distinctUntilChanged, switchMap
|
|
} from 'rxjs/operators';
|
|
|
|
import { Hero } from '../hero';
|
|
import { HeroService } from '../hero.service';
|
|
|
|
@Component({
|
|
selector: 'app-hero-search',
|
|
templateUrl: './hero-search.component.html',
|
|
styleUrls: [ './hero-search.component.css' ]
|
|
})
|
|
export class HeroSearchComponent implements OnInit {
|
|
heroes$: Observable<Hero[]>;
|
|
private searchTerms = new Subject<string>();
|
|
|
|
constructor(private heroService: HeroService) {}
|
|
|
|
// Push a search term into the observable stream.
|
|
search(term: string): void {
|
|
this.searchTerms.next(term);
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.heroes$ = this.searchTerms.pipe(
|
|
// wait 300ms after each keystroke before considering the term
|
|
debounceTime(300),
|
|
|
|
// ignore new term if same as previous term
|
|
distinctUntilChanged(),
|
|
|
|
// switch to new search observable each time the term changes
|
|
switchMap((term: string) => this.heroService.searchHeroes(term)),
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/hero.service.ts]" value="import { Injectable } from '@angular/core';
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
|
|
import { Observable, of } from 'rxjs';
|
|
import { catchError, map, tap } from 'rxjs/operators';
|
|
|
|
import { Hero } from './hero';
|
|
import { MessageService } from './message.service';
|
|
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class HeroService {
|
|
|
|
private heroesUrl = 'api/heroes'; // URL to web api
|
|
|
|
httpOptions = {
|
|
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
|
};
|
|
|
|
constructor(
|
|
private http: HttpClient,
|
|
private messageService: MessageService) { }
|
|
|
|
/** GET heroes from the server */
|
|
getHeroes(): Observable<Hero[]> {
|
|
return this.http.get<Hero[]>(this.heroesUrl)
|
|
.pipe(
|
|
tap(_ => this.log('fetched heroes')),
|
|
catchError(this.handleError<Hero[]>('getHeroes', []))
|
|
);
|
|
}
|
|
|
|
/** GET hero by id. Return `undefined` when id not found */
|
|
getHeroNo404<Data>(id: number): Observable<Hero> {
|
|
const url = `${this.heroesUrl}/?id=${id}`;
|
|
return this.http.get<Hero[]>(url)
|
|
.pipe(
|
|
map(heroes => heroes[0]), // returns a {0|1} element array
|
|
tap(h => {
|
|
const outcome = h ? `fetched` : `did not find`;
|
|
this.log(`${outcome} hero id=${id}`);
|
|
}),
|
|
catchError(this.handleError<Hero>(`getHero id=${id}`))
|
|
);
|
|
}
|
|
|
|
/** GET hero by id. Will 404 if id not found */
|
|
getHero(id: number): Observable<Hero> {
|
|
const url = `${this.heroesUrl}/${id}`;
|
|
return this.http.get<Hero>(url).pipe(
|
|
tap(_ => this.log(`fetched hero id=${id}`)),
|
|
catchError(this.handleError<Hero>(`getHero id=${id}`))
|
|
);
|
|
}
|
|
|
|
/* GET heroes whose name contains search term */
|
|
searchHeroes(term: string): Observable<Hero[]> {
|
|
if (!term.trim()) {
|
|
// if not search term, return empty hero array.
|
|
return of([]);
|
|
}
|
|
return this.http.get<Hero[]>(`${this.heroesUrl}/?name=${term}`).pipe(
|
|
tap(x => x.length ?
|
|
this.log(`found heroes matching "${term}"`) :
|
|
this.log(`no heroes matching "${term}"`)),
|
|
catchError(this.handleError<Hero[]>('searchHeroes', []))
|
|
);
|
|
}
|
|
|
|
//////// Save methods //////////
|
|
|
|
/** POST: add a new hero to the server */
|
|
addHero(hero: Hero): Observable<Hero> {
|
|
return this.http.post<Hero>(this.heroesUrl, hero, this.httpOptions).pipe(
|
|
tap((newHero: Hero) => this.log(`added hero w/ id=${newHero.id}`)),
|
|
catchError(this.handleError<Hero>('addHero'))
|
|
);
|
|
}
|
|
|
|
/** DELETE: delete the hero from the server */
|
|
deleteHero(id: number): Observable<Hero> {
|
|
const url = `${this.heroesUrl}/${id}`;
|
|
|
|
return this.http.delete<Hero>(url, this.httpOptions).pipe(
|
|
tap(_ => this.log(`deleted hero id=${id}`)),
|
|
catchError(this.handleError<Hero>('deleteHero'))
|
|
);
|
|
}
|
|
|
|
/** PUT: update the hero on the server */
|
|
updateHero(hero: Hero): Observable<any> {
|
|
return this.http.put(this.heroesUrl, hero, this.httpOptions).pipe(
|
|
tap(_ => this.log(`updated hero id=${hero.id}`)),
|
|
catchError(this.handleError<any>('updateHero'))
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Handle Http operation that failed.
|
|
* Let the app continue.
|
|
* @param operation - name of the operation that failed
|
|
* @param result - optional value to return as the observable result
|
|
*/
|
|
private handleError<T>(operation = 'operation', result?: T) {
|
|
return (error: any): Observable<T> => {
|
|
|
|
// TODO: send the error to remote logging infrastructure
|
|
console.error(error); // log to console instead
|
|
|
|
// TODO: better job of transforming error for user consumption
|
|
this.log(`${operation} failed: ${error.message}`);
|
|
|
|
// Let the app keep running by returning an empty result.
|
|
return of(result as T);
|
|
};
|
|
}
|
|
|
|
/** Log a HeroService message with the MessageService */
|
|
private log(message: string) {
|
|
this.messageService.add(`HeroService: ${message}`);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/hero.ts]" value="export interface Hero {
|
|
id: number;
|
|
name: string;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/heroes/heroes.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
|
|
import { Hero } from '../hero';
|
|
import { HeroService } from '../hero.service';
|
|
|
|
@Component({
|
|
selector: 'app-heroes',
|
|
templateUrl: './heroes.component.html',
|
|
styleUrls: ['./heroes.component.css']
|
|
})
|
|
export class HeroesComponent implements OnInit {
|
|
heroes: Hero[];
|
|
|
|
constructor(private heroService: HeroService) { }
|
|
|
|
ngOnInit() {
|
|
this.getHeroes();
|
|
}
|
|
|
|
getHeroes(): void {
|
|
this.heroService.getHeroes()
|
|
.subscribe(heroes => this.heroes = heroes);
|
|
}
|
|
|
|
add(name: string): void {
|
|
name = name.trim();
|
|
if (!name) { return; }
|
|
this.heroService.addHero({ name } as Hero)
|
|
.subscribe(hero => {
|
|
this.heroes.push(hero);
|
|
});
|
|
}
|
|
|
|
delete(hero: Hero): void {
|
|
this.heroes = this.heroes.filter(h => h !== hero);
|
|
this.heroService.deleteHero(hero.id).subscribe();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/in-memory-data.service.ts]" value="import { Injectable } from '@angular/core';
|
|
import { InMemoryDbService } from 'angular-in-memory-web-api';
|
|
import { Hero } from './hero';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class InMemoryDataService implements InMemoryDbService {
|
|
createDb() {
|
|
const heroes = [
|
|
{ id: 11, name: 'Dr Nice' },
|
|
{ id: 12, name: 'Narco' },
|
|
{ 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' }
|
|
];
|
|
return {heroes};
|
|
}
|
|
|
|
// Overrides the genId method to ensure that a hero always has an id.
|
|
// If the heroes array is empty,
|
|
// the method below returns the initial number (11).
|
|
// if the heroes array is not empty, the method below returns the highest
|
|
// hero id + 1.
|
|
genId(heroes: Hero[]): number {
|
|
return heroes.length > 0 ? Math.max(...heroes.map(hero => hero.id)) + 1 : 11;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/message.service.ts]" value="import { Injectable } from '@angular/core';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class MessageService {
|
|
messages: string[] = [];
|
|
|
|
add(message: string) {
|
|
this.messages.push(message);
|
|
}
|
|
|
|
clear() {
|
|
this.messages = [];
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/messages/messages.component.ts]" value="import { Component, OnInit } from '@angular/core';
|
|
import { MessageService } from '../message.service';
|
|
|
|
@Component({
|
|
selector: 'app-messages',
|
|
templateUrl: './messages.component.html',
|
|
styleUrls: ['./messages.component.css']
|
|
})
|
|
export class MessagesComponent implements OnInit {
|
|
|
|
constructor(public messageService: MessageService) {}
|
|
|
|
ngOnInit() {
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/mock-heroes.ts]" value="import { Hero } from './hero';
|
|
|
|
export const HEROES: Hero[] = [
|
|
{ id: 11, name: 'Dr Nice' },
|
|
{ id: 12, name: 'Narco' },
|
|
{ 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' }
|
|
];
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/environments/environment.prod.ts]" value="export const environment = {
|
|
production: true
|
|
};
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/environments/environment.ts]" value="// This file can be replaced during build by using the `fileReplacements` array.
|
|
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
|
|
// The list of file replacements can be found in `angular.json`.
|
|
|
|
export const environment = {
|
|
production: false
|
|
};
|
|
|
|
/*
|
|
* For easier debugging in development mode, you can import the following file
|
|
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
|
|
*
|
|
* This import should be commented out in production mode because it will have a negative impact
|
|
* on performance if an error is thrown.
|
|
*/
|
|
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/main.ts]" value="import { enableProdMode } from '@angular/core';
|
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
|
|
|
import { AppModule } from './app/app.module';
|
|
import { environment } from './environments/environment';
|
|
|
|
if (environment.production) {
|
|
enableProdMode();
|
|
}
|
|
|
|
platformBrowserDynamic().bootstrapModule(AppModule)
|
|
.catch(err => console.error(err));
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/polyfills.ts]" value="/**
|
|
* This file includes polyfills needed by Angular and is loaded before the app.
|
|
* You can add your own extra polyfills to this file.
|
|
*
|
|
* This file is divided into 2 sections:
|
|
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
|
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
|
* file.
|
|
*
|
|
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
|
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
|
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
|
*
|
|
* Learn more in https://angular.io/guide/browser-support
|
|
*/
|
|
|
|
/***************************************************************************************************
|
|
* BROWSER POLYFILLS
|
|
*/
|
|
|
|
/** IE11 requires the following for NgClass support on SVG elements */
|
|
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
|
|
|
/**
|
|
* Web Animations `@angular/platform-browser/animations`
|
|
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
|
|
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
|
|
*/
|
|
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
|
|
|
/**
|
|
* By default, zone.js will patch all possible macroTask and DomEvents
|
|
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
|
* because those flags need to be set before `zone.js` being loaded, and webpack
|
|
* will put import in the top of bundle, so user need to create a separate file
|
|
* in this directory (for example: zone-flags.ts), and put the following flags
|
|
* into that file, and then add the following code before importing zone.js.
|
|
* import './zone-flags';
|
|
*
|
|
* The flags allowed in zone-flags.ts are listed here.
|
|
*
|
|
* The following flags will work for all browsers.
|
|
*
|
|
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch
|
|
* requestAnimationFrame
|
|
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
|
|
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch
|
|
* specified eventNames
|
|
*
|
|
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
|
|
* with the following flag, it will bypass `zone.js` patch for IE/Edge
|
|
*
|
|
* (window as any).__Zone_enable_cross_context_check = true;
|
|
*
|
|
*/
|
|
|
|
/***************************************************************************************************
|
|
* Zone JS is required by default for Angular itself.
|
|
*/
|
|
import 'zone.js'; // Included with Angular CLI.
|
|
|
|
/***************************************************************************************************
|
|
* APPLICATION IMPORTS
|
|
*/
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/app.component.css]" value="/* AppComponent's private CSS styles */
|
|
h1 {
|
|
margin-bottom: 0;
|
|
}
|
|
nav a {
|
|
padding: 1rem;
|
|
text-decoration: none;
|
|
margin-top: 10px;
|
|
display: inline-block;
|
|
background-color: #e8e8e8;
|
|
color: #3d3d3d;
|
|
border-radius: 4px;
|
|
}
|
|
nav a:hover {
|
|
color: white;
|
|
background-color: #42545C;
|
|
}
|
|
nav a.active {
|
|
background-color: black;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/dashboard/dashboard.component.css]" value="/* DashboardComponent's private CSS styles */
|
|
|
|
h2 {
|
|
text-align: center;
|
|
}
|
|
|
|
.heroes-menu {
|
|
padding: 0;
|
|
margin: auto;
|
|
max-width: 1000px;
|
|
|
|
/* flexbox */
|
|
display: -webkit-box;
|
|
display: -moz-box;
|
|
display: -ms-flexbox;
|
|
display: -webkit-flex;
|
|
display: flex;
|
|
flex-direction: row;
|
|
flex-wrap: wrap;
|
|
justify-content: space-around;
|
|
align-content: flex-start;
|
|
align-items: flex-start;
|
|
}
|
|
|
|
a {
|
|
background-color: #3f525c;
|
|
border-radius: 2px;
|
|
padding: 1rem;
|
|
font-size: 1.2rem;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
color: #fff;
|
|
text-align: center;
|
|
width: 100%;
|
|
min-width: 70px;
|
|
margin: .5rem auto;
|
|
box-sizing: border-box;
|
|
|
|
/* flexbox */
|
|
order: 0;
|
|
flex: 0 1 auto;
|
|
align-self: auto;
|
|
}
|
|
|
|
@media (min-width: 600px) {
|
|
a {
|
|
width: 18%;
|
|
box-sizing: content-box;
|
|
}
|
|
}
|
|
|
|
a:hover {
|
|
background-color: black;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/hero-detail/hero-detail.component.css]" value="/* HeroDetailComponent's private CSS styles */
|
|
label {
|
|
color: #435960;
|
|
font-weight: bold;
|
|
}
|
|
input {
|
|
font-size: 1em;
|
|
padding: .5rem;
|
|
}
|
|
button {
|
|
margin-top: 20px;
|
|
margin-right: .5rem;
|
|
background-color: #eee;
|
|
padding: 1rem;
|
|
border-radius: 4px;
|
|
font-size: 1rem;
|
|
}
|
|
button:hover {
|
|
background-color: #cfd8dc;
|
|
}
|
|
button:disabled {
|
|
background-color: #eee;
|
|
color: #ccc;
|
|
cursor: auto;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/hero-search/hero-search.component.css]" value="/* HeroSearch private styles */
|
|
|
|
label {
|
|
display: block;
|
|
font-weight: bold;
|
|
font-size: 1.2rem;
|
|
margin-top: 1rem;
|
|
margin-bottom: .5rem;
|
|
|
|
}
|
|
input {
|
|
padding: .5rem;
|
|
width: 100%;
|
|
max-width: 600px;
|
|
box-sizing: border-box;
|
|
display: block;
|
|
}
|
|
|
|
input:focus {
|
|
outline: #336699 auto 1px;
|
|
}
|
|
|
|
li {
|
|
list-style-type: none;
|
|
}
|
|
.search-result li a {
|
|
border-bottom: 1px solid gray;
|
|
border-left: 1px solid gray;
|
|
border-right: 1px solid gray;
|
|
display: inline-block;
|
|
width: 100%;
|
|
max-width: 600px;
|
|
padding: .5rem;
|
|
box-sizing: border-box;
|
|
text-decoration: none;
|
|
color: black;
|
|
}
|
|
|
|
.search-result li a:hover {
|
|
background-color: #435A60;
|
|
color: white;
|
|
}
|
|
|
|
ul.search-result {
|
|
margin-top: 0;
|
|
padding-left: 0;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/heroes/heroes.component.css]" value="/* HeroesComponent's private CSS styles */
|
|
.heroes {
|
|
margin: 0 0 2em 0;
|
|
list-style-type: none;
|
|
padding: 0;
|
|
width: 15em;
|
|
}
|
|
|
|
input {
|
|
display: block;
|
|
width: 100%;
|
|
padding: .5rem;
|
|
margin: 1rem 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.heroes li {
|
|
position: relative;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.heroes li:hover {
|
|
left: .1em;
|
|
}
|
|
|
|
.heroes a {
|
|
color: #333;
|
|
text-decoration: none;
|
|
background-color: #EEE;
|
|
margin: .5em;
|
|
padding: .3em 0;
|
|
height: 1.6em;
|
|
border-radius: 4px;
|
|
display: block;
|
|
width: 100%;
|
|
}
|
|
|
|
.heroes a:hover {
|
|
color: #2c3a41;
|
|
background-color: #e6e6e6;
|
|
}
|
|
|
|
.heroes a:active {
|
|
background-color: #525252;
|
|
color: #fafafa;
|
|
}
|
|
|
|
.heroes .badge {
|
|
display: inline-block;
|
|
font-size: small;
|
|
color: white;
|
|
padding: 0.8em 0.7em 0 0.7em;
|
|
background-color:#405061;
|
|
line-height: 1em;
|
|
position: relative;
|
|
left: -1px;
|
|
top: -4px;
|
|
height: 1.8em;
|
|
min-width: 16px;
|
|
text-align: right;
|
|
margin-right: .8em;
|
|
border-radius: 4px 0 0 4px;
|
|
}
|
|
|
|
.add-button {
|
|
padding: .5rem 1.5rem;
|
|
font-size: 1rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.add-button:hover {
|
|
color: white;
|
|
background-color: #42545C;
|
|
}
|
|
|
|
button.delete {
|
|
position: absolute;
|
|
left: 210px;
|
|
top: 5px;
|
|
background-color: white;
|
|
color: #525252;
|
|
font-size: 1.1rem;
|
|
padding: 1px 10px 3px 10px;
|
|
}
|
|
|
|
button.delete:hover {
|
|
background-color: #525252;
|
|
color: white;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/messages/messages.component.css]" value="/* MessagesComponent's private CSS styles */
|
|
h2 {
|
|
color: #A80000;
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
font-weight: lighter;
|
|
}
|
|
|
|
.clear {
|
|
color: #333;
|
|
background-color: #eee;
|
|
margin-bottom: 12px;
|
|
padding: 1rem;
|
|
border-radius: 4px;
|
|
font-size: 1rem;
|
|
}
|
|
.clear:hover {
|
|
color: #fff;
|
|
background-color: #42545C;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/styles.css]" value="/* Global Styles */
|
|
* {
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
}
|
|
h1 {
|
|
color: #264D73;
|
|
font-size: 2.5rem;
|
|
}
|
|
h2, h3 {
|
|
color: #444;
|
|
font-weight: lighter;
|
|
}
|
|
h3 {
|
|
font-size: 1.3rem;
|
|
}
|
|
body {
|
|
padding: .5rem;
|
|
max-width: 1000px;
|
|
margin: auto;
|
|
}
|
|
@media (min-width: 600px) {
|
|
body {
|
|
padding: 2rem;
|
|
}
|
|
}
|
|
body, input[text] {
|
|
color: #333;
|
|
font-family: Cambria, Georgia, serif;
|
|
}
|
|
a {
|
|
cursor: pointer;
|
|
}
|
|
button {
|
|
background-color: #eee;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
color: black;
|
|
font-size: 1.2rem;
|
|
padding: 1rem;
|
|
margin-right: 1rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
button:hover {
|
|
background-color: black;
|
|
color: white;
|
|
}
|
|
button:disabled {
|
|
background-color: #eee;
|
|
color: #aaa;
|
|
cursor: auto;
|
|
}
|
|
|
|
/* Navigation link styles */
|
|
nav a {
|
|
padding: 5px 10px;
|
|
text-decoration: none;
|
|
margin-right: 10px;
|
|
margin-top: 10px;
|
|
display: inline-block;
|
|
background-color: #e8e8e8;
|
|
color: #3d3d3d;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
nav a:hover {
|
|
color: white;
|
|
background-color: #42545C;
|
|
}
|
|
nav a.active {
|
|
background-color: black;
|
|
color: white;
|
|
}
|
|
hr {
|
|
margin: 1.5rem 0;
|
|
}
|
|
input[type="text"] {
|
|
box-sizing: border-box;
|
|
width: 100%;
|
|
padding: .5rem;
|
|
}
|
|
|
|
|
|
/*
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
*/"><input type="hidden" name="files[src/app/app.component.html]" value="<h1>{{title}}</h1>
|
|
<nav>
|
|
<a routerLink="/dashboard">Dashboard</a>
|
|
<a routerLink="/heroes">Heroes</a>
|
|
</nav>
|
|
<router-outlet></router-outlet>
|
|
<app-messages></app-messages>
|
|
|
|
|
|
<!--
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
-->"><input type="hidden" name="files[src/app/dashboard/dashboard.component.html]" value="<h2>Top Heroes</h2>
|
|
<div class="heroes-menu">
|
|
<a *ngFor="let hero of heroes"
|
|
routerLink="/detail/{{hero.id}}">
|
|
{{hero.name}}
|
|
</a>
|
|
</div>
|
|
|
|
<app-hero-search></app-hero-search>
|
|
|
|
|
|
<!--
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
-->"><input type="hidden" name="files[src/app/hero-detail/hero-detail.component.html]" value="<div *ngIf="hero">
|
|
<h2>{{hero.name | uppercase}} Details</h2>
|
|
<div><span>id: </span>{{hero.id}}</div>
|
|
<div>
|
|
<label for="hero-name">Hero name: </label>
|
|
<input id="hero-name" [(ngModel)]="hero.name" placeholder="Hero name"/>
|
|
</div>
|
|
<button (click)="goBack()">go back</button>
|
|
<button (click)="save()">save</button>
|
|
</div>
|
|
|
|
|
|
<!--
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
-->"><input type="hidden" name="files[src/app/hero-search/hero-search.component.html]" value="<div id="search-component">
|
|
<label for="search-box">Hero Search</label>
|
|
<input #searchBox id="search-box" (input)="search(searchBox.value)" />
|
|
|
|
<ul class="search-result">
|
|
<li *ngFor="let hero of heroes$ | async" >
|
|
<a routerLink="/detail/{{hero.id}}">
|
|
{{hero.name}}
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<!--
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
-->"><input type="hidden" name="files[src/app/heroes/heroes.component.html]" value="<h2>My Heroes</h2>
|
|
|
|
<div>
|
|
<label id="new-hero">Hero name: </label>
|
|
<input for="new-hero" #heroName />
|
|
|
|
<!-- (click) passes input value to add() and then clears the input -->
|
|
<button class="add-button" (click)="add(heroName.value); heroName.value=''">
|
|
Add hero
|
|
</button>
|
|
</div>
|
|
|
|
<ul class="heroes">
|
|
<li *ngFor="let hero of heroes">
|
|
<a routerLink="/detail/{{hero.id}}">
|
|
<span class="badge">{{hero.id}}</span> {{hero.name}}
|
|
</a>
|
|
<button class="delete" title="delete hero"
|
|
(click)="delete(hero)">x</button>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
<!--
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
-->"><input type="hidden" name="files[src/app/messages/messages.component.html]" value="<div *ngIf="messageService.messages.length">
|
|
|
|
<h2>Messages</h2>
|
|
<button class="clear"
|
|
(click)="messageService.clear()">Clear messages</button>
|
|
<div *ngFor='let message of messageService.messages'> {{message}} </div>
|
|
|
|
</div>
|
|
|
|
|
|
<!--
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
-->"><input type="hidden" name="files[src/index.html]" value="<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Tour of Heroes</title>
|
|
<base href="/">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
|
</head>
|
|
<body>
|
|
<app-root></app-root>
|
|
</body>
|
|
</html>
|
|
|
|
|
|
<!--
|
|
Copyright Google LLC. All Rights Reserved.
|
|
Use of this source code is governed by an MIT-style license that
|
|
can be found in the LICENSE file at https://angular.io/license
|
|
-->"><input type="hidden" name="files[angular.json]" value="{
|
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
|
"version": 1,
|
|
"newProjectRoot": "projects",
|
|
"projects": {
|
|
"angular.io-example": {
|
|
"projectType": "application",
|
|
"schematics": {
|
|
"@schematics/angular:application": {
|
|
"strict": true
|
|
}
|
|
},
|
|
"root": "",
|
|
"sourceRoot": "src",
|
|
"prefix": "app",
|
|
"architect": {
|
|
"build": {
|
|
"builder": "@angular-devkit/build-angular:browser",
|
|
"options": {
|
|
"outputPath": "dist",
|
|
"index": "src/index.html",
|
|
"main": "src/main.ts",
|
|
"polyfills": "src/polyfills.ts",
|
|
"tsConfig": "tsconfig.app.json",
|
|
"aot": true,
|
|
"assets": [
|
|
"src/favicon.ico",
|
|
"src/assets"
|
|
],
|
|
"styles": [
|
|
"src/styles.css"
|
|
],
|
|
"scripts": []
|
|
},
|
|
"configurations": {
|
|
"production": {
|
|
"fileReplacements": [
|
|
{
|
|
"replace": "src/environments/environment.ts",
|
|
"with": "src/environments/environment.prod.ts"
|
|
}
|
|
],
|
|
"optimization": true,
|
|
"outputHashing": "all",
|
|
"sourceMap": false,
|
|
"namedChunks": false,
|
|
"extractLicenses": true,
|
|
"vendorChunk": false,
|
|
"buildOptimizer": true,
|
|
"budgets": [
|
|
{
|
|
"type": "initial",
|
|
"maximumWarning": "500kb",
|
|
"maximumError": "1mb"
|
|
},
|
|
{
|
|
"type": "anyComponentStyle",
|
|
"maximumWarning": "2kb",
|
|
"maximumError": "4kb"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"serve": {
|
|
"builder": "@angular-devkit/build-angular:dev-server",
|
|
"options": {
|
|
"browserTarget": "angular.io-example:build"
|
|
},
|
|
"configurations": {
|
|
"production": {
|
|
"browserTarget": "angular.io-example:build:production"
|
|
}
|
|
}
|
|
},
|
|
"extract-i18n": {
|
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
|
"options": {
|
|
"browserTarget": "angular.io-example:build"
|
|
}
|
|
},
|
|
"test": {
|
|
"builder": "@angular-devkit/build-angular:karma",
|
|
"options": {
|
|
"main": "src/test.ts",
|
|
"polyfills": "src/polyfills.ts",
|
|
"tsConfig": "tsconfig.spec.json",
|
|
"karmaConfig": "karma.conf.js",
|
|
"assets": [
|
|
"src/favicon.ico",
|
|
"src/assets"
|
|
],
|
|
"styles": [
|
|
"src/styles.css"
|
|
],
|
|
"scripts": []
|
|
}
|
|
},
|
|
"lint": {
|
|
"builder": "@angular-devkit/build-angular:tslint",
|
|
"options": {
|
|
"tsConfig": [
|
|
"tsconfig.app.json",
|
|
"tsconfig.spec.json",
|
|
"e2e/tsconfig.json"
|
|
],
|
|
"exclude": [
|
|
"**/node_modules/**"
|
|
]
|
|
}
|
|
},
|
|
"e2e": {
|
|
"builder": "@angular-devkit/build-angular:protractor",
|
|
"options": {
|
|
"protractorConfig": "e2e/protractor.conf.js",
|
|
"devServerTarget": "angular.io-example:serve"
|
|
},
|
|
"configurations": {
|
|
"production": {
|
|
"devServerTarget": "angular.io-example:serve:production"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"defaultProject": "angular.io-example"
|
|
}
|
|
"><input type="hidden" name="files[tsconfig.json]" value="{
|
|
"compileOnSave": false,
|
|
"compilerOptions": {
|
|
"baseUrl": "./",
|
|
"outDir": "./dist/out-tsc",
|
|
"forceConsistentCasingInFileNames": true,
|
|
"noImplicitReturns": true,
|
|
"noFallthroughCasesInSwitch": true,
|
|
"sourceMap": true,
|
|
"declaration": false,
|
|
"downlevelIteration": true,
|
|
"experimentalDecorators": true,
|
|
"moduleResolution": "node",
|
|
"importHelpers": true,
|
|
"target": "es2015",
|
|
"module": "es2020",
|
|
"lib": [
|
|
"es2018",
|
|
"dom"
|
|
]
|
|
},
|
|
"angularCompilerOptions": {
|
|
"strictInjectionParameters": true,
|
|
"strictInputAccessModifiers": true,
|
|
"strictTemplates": true,
|
|
"enableIvy": true
|
|
}
|
|
}"><input type="hidden" name="tags[0]" value="angular"><input type="hidden" name="tags[1]" value="example"><input type="hidden" name="tags[2]" value="tutorial"><input type="hidden" name="tags[3]" value="tour"><input type="hidden" name="tags[4]" value="heroes"><input type="hidden" name="tags[5]" value="http"><input type="hidden" name="description" value="Angular Example - Tour of Heroes: Part 6"><input type="hidden" name="dependencies" value="{"@angular/animations":"~11.0.1","@angular/common":"~11.0.1","@angular/compiler":"~11.0.1","@angular/core":"~11.0.1","@angular/forms":"~11.0.1","@angular/platform-browser":"~11.0.1","@angular/platform-browser-dynamic":"~11.0.1","@angular/router":"~11.0.1","angular-in-memory-web-api":"~0.11.0","rxjs":"~6.6.0","tslib":"^2.0.0","zone.js":"~0.11.4","jasmine-core":"~3.6.0","jasmine-marbles":"~0.6.0"}"></form>
|
|
<script>
|
|
var embedded = 'ctl=1';
|
|
var isEmbedded = window.location.search.indexOf(embedded) > -1;
|
|
|
|
if (isEmbedded) {
|
|
var form = document.getElementById('mainForm');
|
|
var action = form.action;
|
|
var actionHasParams = action.indexOf('?') > -1;
|
|
var symbol = actionHasParams ? '&' : '?'
|
|
form.action = form.action + symbol + embedded;
|
|
}
|
|
document.getElementById("mainForm").submit();
|
|
</script>
|
|
</body></html> |