* 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
41 lines
921 B
Dart
41 lines
921 B
Dart
// #docplaster
|
|
// #docregion , v2
|
|
import 'dart:async';
|
|
import 'dart:html';
|
|
|
|
import 'package:angular2/core.dart';
|
|
import 'package:angular2/router.dart';
|
|
|
|
import 'hero.dart';
|
|
import 'hero_service.dart';
|
|
|
|
@Component(
|
|
selector: 'my-hero-detail',
|
|
templateUrl: 'hero_detail_component.html',
|
|
styleUrls: const ['hero_detail_component.css']
|
|
)
|
|
class HeroDetailComponent implements OnInit {
|
|
Hero hero;
|
|
final HeroService _heroService;
|
|
final RouteParams _routeParams;
|
|
|
|
HeroDetailComponent(this._heroService, this._routeParams);
|
|
|
|
Future<Null> ngOnInit() async {
|
|
var idString = _routeParams.get('id');
|
|
var id = int.parse(idString, onError: (_) => null);
|
|
if (id != null) hero = await (_heroService.getHero(id));
|
|
}
|
|
|
|
// #docregion save
|
|
Future<Null> save() async {
|
|
await _heroService.update(hero);
|
|
goBack();
|
|
}
|
|
// #enddocregion save
|
|
|
|
void goBack() {
|
|
window.history.back();
|
|
}
|
|
}
|