* docs(toh-6/dart): refactoring of 'add, edit, delete heroes' Refactoring of "add, edit, delete heroes" section of toh-6 from one big bottom-up step into small independent feature slices, where the user achieves a "milesone" (i.e., can run the full app) after each feature section. The section rewrite is shorter and offers a better UX. Other simplifications: - Error handling is consistent: in the hero service we log to the console, everwhere else we just let errors bubble up. - Hero service methods renamed based on function (create, update) rather then lower-level implementation (post, put). - @Output properties have been eliminated (since they weren't explained). E2E tests now pass on both the TS and Dart sides. * docs(toh-6/ts): refactoring of 'add, edit, delete heroes' Refactoring of "add, edit, delete heroes" section of toh-6 from one big bottom-up step into small independent feature slices, where the user achieves a "milesone" (i.e., can run the full app) after each feature section. The section rewrite is shorter and offers a better UX. Other simplifications: - Error handling is consistent: in the hero service we log to the console, everwhere else we just let errors bubble up. - Hero service methods renamed based on function (create, update) rather then lower-level implementation (post, put). - @Output properties have been eliminated (since they weren't explained). E2E tests now pass on both the TS and Dart sides. Post-Dart-review updates included. * docs(toh-6): ward tweaks
40 lines
890 B
TypeScript
40 lines
890 B
TypeScript
// #docregion
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute, Params } from '@angular/router';
|
|
|
|
import { Hero } from './hero';
|
|
import { HeroService } from './hero.service';
|
|
|
|
@Component({
|
|
selector: 'my-hero-detail',
|
|
templateUrl: 'app/hero-detail.component.html',
|
|
styleUrls: ['app/hero-detail.component.css']
|
|
})
|
|
export class HeroDetailComponent implements OnInit {
|
|
hero: Hero;
|
|
|
|
constructor(
|
|
private heroService: HeroService,
|
|
private route: ActivatedRoute) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.route.params.forEach((params: Params) => {
|
|
let id = +params['id'];
|
|
this.heroService.getHero(id)
|
|
.then(hero => this.hero = hero);
|
|
});
|
|
}
|
|
|
|
// #docregion save
|
|
save(): void {
|
|
this.heroService.update(this.hero)
|
|
.then(this.goBack);
|
|
}
|
|
// #enddocregion save
|
|
|
|
goBack(): void {
|
|
window.history.back();
|
|
}
|
|
}
|