Closed TrentonAdams closed 7 years ago
The issue I submitted appears to have vanished. Very strange.
When I create a data service with createDb like this...
createDb() { const heroes = [ { id: 0, name: 'Zero' }, { id: 11, name: 'Mr. Nice' }, { id: 12, name: 'Narco' }, { id: 13, name: 'Bombasto' }, { id: 14, name: 'Celeritas' }, { id: 15, name: 'Magneta' }, { id: 16, name: 'RubberMan' }, { id: 17, name: 'Dynama' }, { id: 18, name: 'Dr IQ' }, { id: 19, name: 'Magma' }, { id: 20, name: 'Tornado' } ]; return {heroes}; }
And I make a hero service like the following...
@Injectable() export class HeroService { private heroesUrl = 'api/heroes'; constructor(private http: Http) { } getHeroes(): Promise<Hero[]> { return this.http.get(this.heroesUrl) .toPromise() .then(response => response.json().data as Hero[]) .catch(this.handleError); } private handleError(error: any): Promise<any> { console.error('An error occurred', error); // for demo purposes only return Promise.reject(error.message || error); } getHero(id: number): Promise<Hero> { const url = `${this.heroesUrl}/${id}`; console.log('angular log'); return this.http.get(this.heroesUrl) .toPromise() .then(response => response.json().data as Hero) .catch(this.handleError); } }
Both getHero(id) and getHeroes() return the exact same result, namely an array of heroes.
Am I doing it wrong, or is this a bug?
But shouldn't you be passing in "url" to the getHero this.http.get function instead of "this.heroesUrl"?
@Kandium is exactly right. Closing.
The issue I submitted appears to have vanished. Very strange.
When I create a data service with createDb like this...
And I make a hero service like the following...
Both getHero(id) and getHeroes() return the exact same result, namely an array of heroes.
Am I doing it wrong, or is this a bug?