I created my app using angular-cli
.
I wrote service GameService
for getting data from json file:
import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class GameService {
constructor(private http: Http) { }
getGames() {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.get('app/shared/games.json', options)
.map((res: Response) => res.json());
}
}
Also I created model Game
:
export class Game {
title: String;
image: String;
cost: String;
}
I imported the service and the model in my AppModule
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { GameService } from './shared/services/game.service';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpModule
],
providers: [
GameService
],
bootstrap: [AppComponent]
})
export class AppModule { }
Loading application I get an error:
GET http://localhost:4200/app/shared/games.json 404 (Not Found)
Below is structure application:
I don't understand where I made the error exactly. I searched and saw many questions and answers to it on stackoverlow but it didn't help.
Please, help me.