docs: fix issues related to tutorial. (#24445)

PR Close #24445
This commit is contained in:
Vani
2018-06-12 07:42:17 +05:30
committed by Kara Erickson
parent 6a62ed2245
commit c7e2930f25
6 changed files with 58 additions and 19 deletions

View File

@ -1,5 +1,6 @@
// #docregion , init
import { InMemoryDbService } from 'angular-in-memory-web-api';
import { Hero } from './hero';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
@ -17,4 +18,13 @@ export class InMemoryDataService implements InMemoryDbService {
];
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;
}
}