Skip to content
Snippets Groups Projects
Commit 63baebe9 authored by Maxime POULAIN's avatar Maxime POULAIN
Browse files

wip

parent 0df37322
No related branches found
No related tags found
No related merge requests found
Showing
with 95 additions and 14 deletions
No preview for this file type
......@@ -4,11 +4,13 @@ import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes/heroes.component';
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
@NgModule({
declarations: [
AppComponent,
HeroesComponent
HeroesComponent,
HeroDetailComponent
],
imports: [
BrowserModule,
......
<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="name">
</div>
</div>
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HeroDetailComponent } from './hero-detail.component';
describe('HeroDetailComponent', () => {
let component: HeroDetailComponent;
let fixture: ComponentFixture<HeroDetailComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ HeroDetailComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(HeroDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit, Input } from '@angular/core';
import { Hero } from '../hero';
@Component({
selector: 'app-hero-detail',
templateUrl: './hero-detail.component.html',
styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {
@Input() hero?: Hero;
constructor() { }
ngOnInit(): void {
}
}
import { TestBed } from '@angular/core/testing';
import { HeroService } from './hero.service';
describe('HeroService', () => {
let service: HeroService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(HeroService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { Observable, of } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class HeroService {
getHeroes(): Observable<Hero[]> {
const heroes = of(HEROES);
return heroes;
}
constructor() { }
}
......@@ -7,13 +7,4 @@
</li>
</ul>
<div *ngIf="selectedHero">
<h2>{{selectedHero.name | uppercase}} Details</h2>
<div><span>id: </span>{{selectedHero.id}}</div>
<div>
<label for="hero-name">Hero name: </label>
<input id="hero-name" [(ngModel)]="selectedHero.name" placeholder="name">
</div>
</div>
<app-hero-detail [hero]="selectedHero"></app-hero-detail>
import { Component, OnInit } from '@angular/core';
import { Hero } from '../hero';
import { HeroService } from '../hero.service';
import { HEROES } from '../mock-heroes';
......@@ -9,15 +10,19 @@ import { HEROES } from '../mock-heroes';
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
heroes = HEROES;
heroes?: Hero[];
selectedHero?: Hero;
getHeroes(): void {
this.heroes = this.heroService.getHeroes();
}
constructor(private heroService: HeroService) {
constructor() {
this.selectedHero = this.heroes[0];
}
ngOnInit(): void {
this.getHeroes();
}
onSelect(hero: Hero): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment