29
loading...
This website collects cookies to deliver better user experience
ng g s animal
export interface IAnimal {
guid: string;
name: string;
type: string;
description: string;
numberAtZoo: number;
photo: string;
animalInResidence: IAnimalInResidence[];
food: IFood[];
habitats: IHabitat[];
}
export interface IAnimalInResidence {
name: string;
personality: string;
age: number;
}
export interface IFood {
foodName: string;
}
export interface IHabitat {
habitatName: string;
}
export abstract class AnimalService {
abstract getAll(): Observable<IAnimal[]>;
abstract get(id: string): Observable<IAnimal>;
}
export class MockAnimalService extends AnimalService { … }
export class MockAnimalService extends AnimalService {
getAll(): Observable<IAnimal[]> {
return of([
new Animal1(),
new Animal2(),
new Animal3()
]);
}
}
get(guid: string): Observable<IAnimal> {
return this.getAll()
.pipe(
map(x => x.find(a => a.guid === guid))
);
}
{path: 'animals/:guid', component: AnimalComponent}
<a [routerLink]="['/animals', animal.guid]">{{animal.name}} </a>
<main class="animal-wrapper">
<h1>{{animal.name}}</h1>
<h3>{{animal.type}}</h3>
<p>{{animal.description}}</p>
<h5 *ngFor="let foodItem of animal.food">{{foodItem.name}}</h5>
<h5 *ngFor="let habitat of animal.habitats">{{location.name}}</h5>
...
</main>