1 import { Injectable } from '@angular/core';
2 import { InMemoryDbService } from 'angular-in-memory-web-api';
3 import { Hero } from './hero';
8 export class InMemoryDataService implements InMemoryDbService {
11 { id: 11, name: 'Dr Nice' },
12 { id: 12, name: 'Narco' },
13 { id: 13, name: 'Bombasto' },
14 { id: 14, name: 'Celeritas' },
15 { id: 15, name: 'Magneta' },
16 { id: 16, name: 'RubberMan' },
17 { id: 17, name: 'Dynama' },
18 { id: 18, name: 'Dr IQ' },
19 { id: 19, name: 'Magma' },
20 { id: 20, name: 'Tornado' }
25 // Overrides the genId method to ensure that a hero always has an id.
26 // If the heroes array is empty,
27 // the method below returns the initial number (11).
28 // if the heroes array is not empty, the method below returns the highest
30 genId(heroes: Hero[]): number {
31 return heroes.length > 0 ? Math.max(...heroes.map(hero => hero.id)) + 1 : 11;